結果
問題 | No.619 CardShuffle |
ユーザー | heyshb |
提出日時 | 2017-12-19 11:29:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,645 bytes |
コンパイル時間 | 1,664 ms |
コンパイル使用メモリ | 159,728 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-12-22 21:47:56 |
合計ジャッジ時間 | 20,667 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
8,960 KB |
testcase_01 | AC | 2 ms
10,624 KB |
testcase_02 | AC | 2 ms
9,216 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 445 ms
5,248 KB |
testcase_17 | AC | 182 ms
5,248 KB |
testcase_18 | AC | 362 ms
5,248 KB |
testcase_19 | AC | 188 ms
5,248 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 450 ms
5,248 KB |
testcase_22 | AC | 159 ms
5,248 KB |
testcase_23 | AC | 465 ms
5,248 KB |
testcase_24 | AC | 159 ms
5,248 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 292 ms
5,248 KB |
testcase_27 | AC | 217 ms
5,248 KB |
testcase_28 | AC | 292 ms
5,248 KB |
testcase_29 | AC | 215 ms
5,248 KB |
testcase_30 | AC | 960 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | TLE | - |
testcase_33 | AC | 231 ms
5,248 KB |
testcase_34 | AC | 312 ms
5,248 KB |
testcase_35 | AC | 40 ms
10,624 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:122:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 122 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:133:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 133 | scanf("%s",tmp); | ~~~~~^~~~~~~~~~ main.cpp:143:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 143 | scanf("%d",&Q); | ~~~~~^~~~~~~~~ main.cpp:148:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 148 | scanf("%s",tmp); | ~~~~~^~~~~~~~~~ main.cpp:149:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 149 | scanf("%d%d",&x,&y); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MOD = 1e9+7; int N; char v[100010]; const int blk = 300; int bl[100010],L[100010],R[100010]; int S[blk*10],rv[blk*10],lv[blk*10],mv[blk*10],B; bool oneblk[blk]; int fp[blk*10],lp[blk*10]; void upd(int &x) { if (x < 0) x += MOD; if (x >= MOD) x -= MOD; } int calc(int l,int r)//num---num { int sum = 0,nowv = 1; //printf("calc %d %d\n",l,r); for (int i=l;i<=r;i+=2) { nowv = (1LL * nowv * (v[i] - '0')) % MOD; //printf("%d %d\n",i,nowv); if (v[i+1] == '+' || i==r) { upd(sum += nowv); nowv = 1; } } //printf("calc %d %d=%d\n",l,r,sum); return sum; } void build(int b) { fp[b] = lp[b] = 0; for (int i=L[b];i<R[b];i++) { if (v[i] == '+') { if (!fp[b]) fp[b] = i; lp[b] = i; } } S[b] = calc(L[b],R[b]-1); lv[b] = calc(L[b],fp[b]-1); rv[b] = calc(lp[b]+1,R[b]-1); mv[b] = calc(fp[b]+1,lp[b]-1); } int query(int x,int y) { //printf("query %d %d\n",x,y); if (bl[x] == bl[y]) return calc(x,y); int sum = 0,nowv = 1; for (int i=x;i<R[bl[x]];i+=2) { nowv = 1LL * nowv * (v[i] - '0') % MOD; if (v[i+1] == '+') { upd(sum += nowv); nowv = 1; } } //printf("%d %d\n",sum,nowv); for (int i=bl[x]+1;i<bl[y];i++) { if (v[R[i]] == '+') { if (fp[i]) { nowv = 1LL * nowv * lv[i] % MOD; upd(sum += nowv); upd(sum += S[i]); upd(sum -= lv[i]); } else { nowv = 1LL * nowv * S[i] % MOD; upd(sum += nowv); } nowv = 1; } else { if (fp[i]) { nowv = 1LL * nowv * lv[i] % MOD; upd(sum += nowv); upd(sum += mv[i]); nowv = rv[i]; } else { nowv = 1LL * nowv * S[i] % MOD; } } //printf("%d %d\n",sum,nowv); } for (int i=L[bl[y]];i<=y;i+=2) { nowv = 1LL * nowv * (v[i] - '0') % MOD; if (v[i+1] == '+' || i==y) { upd(sum += nowv); nowv = 1; } } //printf("%d %d\n",sum,nowv); return sum; } int main() { //freopen("619.in","r",stdin); //freopen("619.out","w",stdout); scanf("%d",&N); for (int i=1;i<=N;i++)bl[i] = (i - 1) / blk + 1; B = bl[N]; for (int i=1;i<=N;i++) { if (bl[i] != bl[i-1]) L[bl[i]] = i; if (bl[i] != bl[i+1]) R[bl[i]] = i; } for (int i=1;i<=N;i++) { char tmp[2]; scanf("%s",tmp); v[i] = tmp[0]; } for (int i=1;i<=B;i++) { build(i); //printf("%d: fp=%d lp=%d S=%d\n",i,fp[i],lp[i],S[i]); } int Q; scanf("%d",&Q); while(Q--) { char tmp[2]; int x,y; scanf("%s",tmp); scanf("%d%d",&x,&y); if (tmp[0] == '?') { printf("%d\n",query(x,y)); } else { if (v[x] != v[y]) { swap(v[x],v[y]); build(bl[x]); build(bl[y]); } } } }