Submission #13263

# Submission time Handle Problem Language Result Execution time Memory
13263 2015-02-07T04:18:04 Z dohyun0324 Collider (IZhO11_collider) C++
10 / 100
21 ms 17872 KB
#include<stdio.h>
#include<math.h>
int x,y,w,n,k,m,top[1010];
char arr[1000010],dap,t,a[1000010],c,bucket[1010][15010];
void update(int x,int y)
{
    int i,j,cnt=0,r;
    for(i=1;i<=w;i++){
        if(top[i]+cnt>=x){
            for(j=1;j<=k*2;j++){
                if(bucket[i][j]!=0) cnt++;
                if(cnt==x){t=bucket[i][j]; bucket[i][j]=0, top[i]--;break;}
            }
            break;
        }
        cnt+=top[i];
    }
    cnt=0;
    for(i=1;i<=w;i++){
        if(top[i]+cnt>=y){
            for(j=1;j<=k*2;j++){
                if(bucket[i][j]!=0) cnt++;
                if(cnt==y) break;
            }
            for(r=k*2;r>=j+1;r--) bucket[i][r]=bucket[i][r-1];
            bucket[i][j]=t; top[i]++;
            break;
        }
        cnt+=top[i];
    }
}
char query(int x)
{
    int i,j,cnt=0;
    for(i=1;i<=w;i++){
        if(top[i]+cnt>=x){
            for(j=1;j<=k*2;j++){
                if(bucket[i][j]!=0) cnt++;
                if(cnt==x) return bucket[i][j];
            }
            break;
        }
        cnt+=top[i];
    }
}
void clearing()
{
    int i,j,cnt=0;
    for(i=1;i<=w;i++){
        for(j=1;j<=k*2;j++){
            if(bucket[i][j]!=0) arr[++cnt]=bucket[i][j];
        }
    }
    for(i=1;i<=n;i++){
        if(i%k==1) w++;
        bucket[w][++top[w]]=arr[i];
    }
}
int main()
{
    int i;
    scanf("%d %d",&n,&m);
    scanf("%s",a);
    for(i=n;i>=1;i--) a[i]=a[i-1]; a[0]=0;
    k=sqrt(n);
    for(i=1;i<=n;i++)
    {
        if(i%k==1) w++;
        bucket[w][++top[w]]=a[i];
    }
    for(i=1;i<=m;i++)
    {
        scanf(" %c",&c);
        if(c=='a'){
            scanf("%d %d",&x,&y);
            update(x,y);
        }
        else{
            scanf("%d",&x);
            dap=query(x);
            printf("%c\n",dap);
        }
        if(i%k==0) clearing();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17872 KB Output is correct
2 Runtime error 6 ms 17872 KB SIGSEGV Segmentation fault
3 Runtime error 7 ms 17872 KB SIGSEGV Segmentation fault
4 Runtime error 16 ms 17872 KB SIGSEGV Segmentation fault
5 Runtime error 17 ms 17872 KB SIGSEGV Segmentation fault
6 Runtime error 19 ms 17872 KB SIGSEGV Segmentation fault
7 Runtime error 20 ms 17872 KB SIGSEGV Segmentation fault
8 Runtime error 19 ms 17872 KB SIGSEGV Segmentation fault
9 Runtime error 19 ms 17872 KB SIGSEGV Segmentation fault
10 Runtime error 21 ms 17872 KB SIGSEGV Segmentation fault