답안 #13264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13264 2015-02-07T04:22:47 Z dohyun0324 입자 가속기 (IZhO11_collider) C++
0 / 100
35 ms 11924 KB
#include<stdio.h>
#include<math.h>
int x,y,w,n,k,m,top[3010];
char arr[1000010],dap,t,a[1000010],c,bucket[3010][3010];
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];
        }
    }
    w=0;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 11924 KB Output isn't correct
2 Incorrect 6 ms 11924 KB Output isn't correct
3 Incorrect 21 ms 11924 KB Output isn't correct
4 Runtime error 20 ms 11924 KB SIGSEGV Segmentation fault
5 Runtime error 26 ms 11924 KB SIGSEGV Segmentation fault
6 Runtime error 30 ms 11924 KB SIGSEGV Segmentation fault
7 Runtime error 33 ms 11924 KB SIGSEGV Segmentation fault
8 Runtime error 31 ms 11924 KB SIGSEGV Segmentation fault
9 Runtime error 27 ms 11924 KB SIGSEGV Segmentation fault
10 Runtime error 35 ms 11924 KB SIGSEGV Segmentation fault