結果
| 問題 | No.619 CardShuffle | 
| コンテスト | |
| ユーザー |  %20 | 
| 提出日時 | 2017-12-25 19:47:04 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 96 ms / 3,000 ms | 
| コード長 | 1,452 bytes | 
| コンパイル時間 | 373 ms | 
| コンパイル使用メモリ | 31,488 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-12-22 23:13:35 | 
| 合計ジャッジ時間 | 3,534 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 35 | 
コンパイルメッセージ
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<<17];
      | ^~~
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);
      |           
            
            ソースコード
const mod=1000000007;
typedef struct{
	long long a,b,c;
	char o;
}abc;
abc C[1<<18];
idx[1<<17];
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);
		}
	}
}
            
            
            
        