結果
問題 | No.619 CardShuffle |
ユーザー | tails |
提出日時 | 2017-12-19 12:19:43 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 104 ms / 3,000 ms |
コード長 | 1,705 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 31,232 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-22 21:50:06 |
合計ジャッジ時間 | 3,826 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 4 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,816 KB |
testcase_06 | AC | 3 ms
6,816 KB |
testcase_07 | AC | 4 ms
6,820 KB |
testcase_08 | AC | 3 ms
6,820 KB |
testcase_09 | AC | 3 ms
6,816 KB |
testcase_10 | AC | 3 ms
6,816 KB |
testcase_11 | AC | 3 ms
6,816 KB |
testcase_12 | AC | 3 ms
6,820 KB |
testcase_13 | AC | 4 ms
6,816 KB |
testcase_14 | AC | 3 ms
6,820 KB |
testcase_15 | AC | 3 ms
6,816 KB |
testcase_16 | AC | 99 ms
6,820 KB |
testcase_17 | AC | 88 ms
6,816 KB |
testcase_18 | AC | 104 ms
6,820 KB |
testcase_19 | AC | 89 ms
6,816 KB |
testcase_20 | AC | 89 ms
6,820 KB |
testcase_21 | AC | 98 ms
6,816 KB |
testcase_22 | AC | 83 ms
6,820 KB |
testcase_23 | AC | 99 ms
6,816 KB |
testcase_24 | AC | 85 ms
6,820 KB |
testcase_25 | AC | 87 ms
6,820 KB |
testcase_26 | AC | 98 ms
6,816 KB |
testcase_27 | AC | 86 ms
6,820 KB |
testcase_28 | AC | 100 ms
6,820 KB |
testcase_29 | AC | 88 ms
6,816 KB |
testcase_30 | AC | 88 ms
6,816 KB |
testcase_31 | AC | 3 ms
6,820 KB |
testcase_32 | AC | 90 ms
6,820 KB |
testcase_33 | AC | 95 ms
6,820 KB |
testcase_34 | AC | 81 ms
6,816 KB |
testcase_35 | AC | 38 ms
6,816 KB |
コンパイルメッセージ
main.c:94:1: warning: return type defaults to 'int' [-Wimplicit-int] 94 | main(n,q,i,t,x,y){ | ^~~~ main.c: In function 'main': main.c:94:1: warning: type of 'n' defaults to 'int' [-Wimplicit-int] main.c:94:1: warning: type of 'q' defaults to 'int' [-Wimplicit-int] main.c:94:1: warning: type of 'i' defaults to 'int' [-Wimplicit-int] main.c:94:1: warning: type of 't' defaults to 'int' [-Wimplicit-int] main.c:94:1: warning: type of 'x' defaults to 'int' [-Wimplicit-int] main.c:94:1: warning: type of 'y' defaults to 'int' [-Wimplicit-int] main.c:95:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 95 | scanf("%d",&n); | ^~~~~ main.c:2:1: note: include '<stdio.h>' or provide a declaration of 'scanf' 1 | #include <assert.h> +++ |+#include <stdio.h> 2 | main.c:95:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 95 | scanf("%d",&n); | ^~~~~ main.c:95:9: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:114:25: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 114 | printf("%d\n",(0ll+nd.l+nd.r+nd.m)%M); | ^~~~~~ main.c:114:25: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:114:25: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:114:25: note: include '<stdio.h>' or provide a declaration of 'printf'
ソースコード
#include <assert.h> #define M 1000000007 typedef struct{ int l,r,m; } N; N ns[1<<17]; int ds[1<<17]; void nmul(N*p1,N*p2,N*pd){ if(p1->r<0){ pd->l=1ll*p1->l*p2->l%M; if(p2->r<0){ pd->r=-1; pd->m=1; }else{ pd->r=p2->r; pd->m=p2->m; } }else{ pd->l=p1->l; if(p2->r<0){ pd->r=1ll*p1->r*p2->l%M; pd->m=p1->m; }else{ pd->r=p2->r; pd->m=(p1->m+1ll*p1->r*p2->l+p2->m)%M; } } } void nadd(N*p1,N*p2,N*pd){ pd->l=p1->l; if(p2->r<0){ pd->r=p2->l; if(p1->r<0&&p2->r<0){ pd->m=0; }else{ pd->m=(p1->r+p1->m)%M; } }else{ pd->r=p2->r; if(p1->r<0){ pd->m=(p2->l+p2->m)%M; }else{ pd->m=(0ll+p1->m+p1->r+p2->l+p2->m)%M; } } } void ncalc(N*p1,N*p2,N*pd,int op){ (op=='*'?nmul:nadd)(p1,p2,pd); } void mk(int l,int r,int i,int j){ int i1=i*2+1; int i2=i*2+2; if(l==r-1){ // leaf ns[i].l=ds[l*2]; ns[i].r=-1; ns[i].m=1; }else{ // inter int c=(l+r)/2; if(j<0||j<c)mk(l,c,i1,j); if(j<0||j>=c)mk(c,r,i2,j); ncalc(ns+i1,ns+i2,ns+i,ds[l+r-1]); } } N f(int l,int r,int i,int x,int y){ if(x<=l&&y>=r){ return ns[i]; } int c=(l+r)/2; if(y<=c){ return f(l,c,i*2+1,x,y); } if(x>=c){ return f(c,r,i*2+2,x,y); } { N nd; N nl=f(l,c,i*2+1,x,y); N nr=f(c,r,i*2+2,x,y); ncalc(&nl,&nr,&nd,ds[l+r-1]); return nd; } } main(n,q,i,t,x,y){ scanf("%d",&n); scanf("%d",ds); for(i=1;i<n;i+=2){ scanf(" %s%d",ds+i,ds+i+1); } mk(0,1<<16,0,-1); scanf("%d",&q); for(i=0;i<q;++i){ t=0; scanf(" %s%d%d",&t,&x,&y); if(t=='!'){ t=ds[x-1]; ds[x-1]=ds[y-1]; ds[y-1]=t; mk(0,1<<16,0,x/2); mk(0,1<<16,0,y/2); }else{ N nd=f(0,1<<16,0,x/2,y/2+1); printf("%d\n",(0ll+nd.l+nd.r+nd.m)%M); } } }