A. Sereja and Prefixes----模拟

A. Sereja and Prefixes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.

Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new number to the end of the sequence or takes l first elements of the current sequence and adds them c times to the end. More formally, if we represent the current sequence as a1, a2, ..., an, then after we apply the described operation, the sequence transforms into a1, a2, ..., an[, a1, a2, ..., al] (the block in the square brackets must be repeated c times).

A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja.

Input

The first line contains integer m (1 ≤ m ≤ 105) — the number of stages to build a sequence.

Next m lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer xi (1 ≤ xi ≤ 105) — the number to add. Type 2 means copying a prefix of length li to the end ci times, in this case the line further contains two integers li, ci (1 ≤ li ≤ 105, 1 ≤ ci ≤ 104)li is the length of the prefix, ci is the number of copyings. It is guaranteed that the length of prefix li is never larger than the current length of the sequence.

The next line contains integer n (1 ≤ n ≤ 105) — the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Output

Print the elements that Sereja is interested in, in the order in which their numbers occur in the input.

Examples
input
6
1 1
1 2
2 2 1
1 3
2 5 2
1 4
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
output
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4

题目链接:http://codeforces.com/contest/380/problem/A


题目的意思是说给出m次操作,分别有1:在序列最后加上x;2:复制1~x,y次,添加在序列尾部。然后给出n次查询,问说在第k[i]个位置上的数是多少。

因为x不会大于10^5,就是说复制的部分最多就10^5,那么久可以在一开始将前10^5个数记录下来,后面只需要遍历n的同时移动m即可

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
const int N=100005;
struct node{
    int s;
    LL x,y;
}xin[N];
int n,m,num[N],ans[N],c,cnt;
LL k[N];
void handle(){
    c=0;
    for(int i=0;i<m;i++){
        if(xin[i].s==1){
            num[c++]=xin[i].x;
            if(c>=100000)
                return;
        }
        else{
            for(LL t=0;t<xin[i].y;t++){
                for (LL j=0;j<xin[i].x;j++){
                    num[c++]=num[j];
                    if(c>=100000)
                        return;
                }
            }
        }
    }
}
void solve(){
    int i=0,j=0;
    LL p=0;
    while(i<n){
        while(j<m){
            if(xin[j].s==1){
                p++;
                j++;
                if(p==k[i]){
                    ans[i]=xin[j-1].x;
                    i++;
                    if(i>=n)
                        return;
                    break;
                }
            }
            else{
                LL q=p;
                p+=xin[j].x*xin[j].y;
                if(p>=k[i]){
                    while(i<n){
                        if(k[i]<=p){
                            ans[i]=num[(k[i]-q-1)%xin[j].x%100000];
                            i++;
                            if(i>=n)
                                return ;
                        }
                        else{
                            j++;
                            break;
                        }
                    }
                }
                else
                    j++;
            }
        }
    }
}
int main(){
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d",&xin[i].s);
        if(xin[i].s==1)
            cin>>xin[i].x;
        else
            cin>>xin[i].x>>xin[i].y;
    }
    handle();
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        cin>>k[i];
    solve();
    printf("%d",ans[0]);
    for(int i=1;i<n;i++)
        printf(" %d",ans[i]);
    printf("\n");
    return 0;
}


Execution failed for task ':app:externalNativeBuildDebug'. > Build command failed. Error while executing process D:\NDK\android-sdk-windows\cmake\3.22.1\bin\ninja.exe with arguments {-C E:\desktop\MyApplication\app\.cxx\cmake\debug\armeabi-v7a myapplication} ninja: Entering directory `E:\desktop\MyApplication\app\.cxx\cmake\debug\armeabi-v7a' [1/2] Building CXX object CMakeFiles/myapplication.dir/native-lib.cpp.o FAILED: CMakeFiles/myapplication.dir/native-lib.cpp.o D:\NDK\android-sdk-windows\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi24 --gcc-toolchain=D:/NDK/android-sdk-windows/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/NDK/android-sdk-windows/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot -Dmyapplication_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/myapplication.dir/native-lib.cpp.o -MF CMakeFiles\myapplication.dir\native-lib.cpp.o.d -o CMakeFiles/myapplication.dir/native-lib.cpp.o -c E:/desktop/MyApplication/app/src/main/cpp/native-lib.cpp E:/desktop/MyApplication/app/src/main/cpp/native-lib.cpp:3:10: fatal error: 'opencv2/core.hpp' file not found #include <opencv2/core.hpp> ^~~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: subcommand failed. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights.
最新发布
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值