結果

問題 No.619 CardShuffle
ユーザー %20%20
提出日時 2017-12-25 19:43:29
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,452 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-02 05:23:23
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 1 ms
5,376 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 35 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:7: warning: type defaults to 'int' in declaration of 'mod' [-Wimplicit-int]
    1 | const mod=1000000007;
      |       ^~~
main.c:9:1: warning: data definition has no type or storage class
    9 | idx[1<<16];
      | ^~~
main.c:9:1: warning: type defaults to 'int' in declaration of 'idx' [-Wimplicit-int]
main.c:10:1: warning: data definition has no type or storage class
   10 | CN;
      | ^~
main.c:10:1: warning: type defaults to 'int' in declaration of 'CN' [-Wimplicit-int]
main.c:11:1: warning: data definition has no type or storage class
   11 | N,Q,X,Y;
      | ^
main.c:11:1: warning: type defaults to 'int' in declaration of 'N' [-Wimplicit-int]
main.c:11:3: warning: type defaults to 'int' in declaration of 'Q' [-Wimplicit-int]
   11 | N,Q,X,Y;
      |   ^
main.c:11:5: warning: type defaults to 'int' in declaration of 'X' [-Wimplicit-int]
   11 | N,Q,X,Y;
      |     ^
main.c:11:7: warning: type defaults to 'int' in declaration of 'Y' [-Wimplicit-int]
   11 | N,Q,X,Y;
      |       ^
main.c:63:1: warning: return type defaults to 'int' [-Wimplicit-int]
   63 | d(i){
      | ^
main.c: In function 'd':
main.c:63:1: warning: type of 'i' defaults to 'int' [-Wimplicit-int]
main.c:67:25: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   67 |                         scanf("%c%*c",&C[i].o);
      |                         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | const mod=1000000007;
main.c:67:25: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   67 |                         scanf("%c%*c",&C[i].o);
      |                         ^~~~~
main.c:67:25: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:74:17: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   74 |                 scanf("%lld%*c",&C[i].b);
      |           

ソースコード

diff #

const mod=1000000007;

typedef struct{
	long long a,b,c;
	char o;
}abc;
abc C[1<<18];

idx[1<<16];
CN;
N,Q,X,Y;
char T;

abc op(char o,abc A,abc B){
	abc R;
	if(o){
		if(A.b>=0){
			if(B.b>=0){
				R.a=A.a;
				R.b=(A.b+A.c*B.a+B.b)%mod;
				R.c=B.c;
			}else{
				R.a=A.a;
				R.b=A.b;
				R.c=A.c*-B.b%mod;
			}
		}else{
			if(B.b>=0){
				R.a=-A.b*B.a%mod;
				R.b=B.b;
				R.c=B.c;
			}else{
				R.b=-(-A.b*-B.b%mod);
			}
		}
	}else{
		if(A.b>=0){
			if(B.b>=0){
				R.a=A.a;
				R.b=(A.b+A.c+B.a+B.b)%mod;
				R.c=B.c;
			}else{
				R.a=A.a;
				R.b=(A.b+A.c)%mod;
				R.c=-B.b;
			}
		}else{
			if(B.b>=0){
				R.a=-A.b;
				R.b=(B.a+B.b)%mod;
				R.c=B.c;
			}else{
				R.a=-A.b;
				R.b=0;
				R.c=-B.b;
			}
		}
	}
	R.o=o;
	return R;
}

d(i){
	if(i<65536){
		d(i*2);
		if(CN<N){
			scanf("%c%*c",&C[i].o);
			C[i].o^='+';
			idx[++CN]=i;
			d(i*2+1);
		}
		C[i]=op(C[i].o,C[i*2],C[i*2+1]);
	}else{
		scanf("%lld%*c",&C[i].b);
		C[i].b*=-1;
		idx[++CN]=i;
	}
}

r(i){
	C[i]=op(C[i].o,C[i*2],C[i*2+1]);
	if(i>1)r(i/2);
}

main(){
	scanf("%d%*c",&N);
	d(1);
	scanf("%d%*c",&Q);
	for(;Q--;){
		scanf("%c%d%d%*c",&T,&X,&Y);
		int x=idx[X],y=idx[Y];
		if(T=='!'){
			abc t=C[x];C[x]=C[y];C[y]=t;
			r(x>>X%2);
			r(y>>Y%2);
		}else{
			abc t=C[x],u=C[y];
			for(;x/2<y/2;x/=2,y/=2){
				if(x%2==0)t=op(C[x/2].o,t,C[x+1]);
				if(y%2==1)u=op(C[y/2].o,C[y-1],u);
			}
			t=op(C[x/2].o,t,u);
			printf("%lld\n",(t.b<0?-t.b:t.a+t.b+t.c)%mod);
		}
	}
}
0