結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | LayCurse |
提出日時 | 2015-06-21 01:39:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 6,249 bytes |
コンパイル時間 | 1,480 ms |
コンパイル使用メモリ | 171,116 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-07 15:24:22 |
合計ジャッジ時間 | 3,162 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 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 | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 6 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 62 ms
7,040 KB |
testcase_10 | AC | 36 ms
5,376 KB |
testcase_11 | AC | 34 ms
5,376 KB |
testcase_12 | AC | 62 ms
7,040 KB |
testcase_13 | AC | 9 ms
5,376 KB |
testcase_14 | AC | 9 ms
8,832 KB |
testcase_15 | AC | 81 ms
8,832 KB |
testcase_16 | AC | 74 ms
9,984 KB |
testcase_17 | AC | 138 ms
10,752 KB |
testcase_18 | AC | 39 ms
10,752 KB |
testcase_19 | AC | 85 ms
10,880 KB |
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’: main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | void reader(double *x){scanf("%lf",x);} | ~~~~~^~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) #define ll long long #define ull unsigned ll void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(double *x){scanf("%lf",x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);} template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(double x, char c){printf("%.15f",x);mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template<class T> void writerLn(T x){writer(x,'\n');} template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} char memarr[17000000]; void *mem = memarr; #define MD 1000000007 template<class T> struct lazySegtreeSum{ int size, mem; T *val, *sum, *addStock, *changeStock; char *changeFlag; void malloc(int N){ mem = N; val = (T*)std::malloc(sizeof(T)*N); sum = (T*)std::malloc(sizeof(T)*N*4); addStock = (T*)std::malloc(sizeof(T)*N*4); changeStock = (T*)std::malloc(sizeof(T)*N*4); changeFlag = (char*)std::malloc(sizeof(char)*N*4); } void free(void){ mem = 0; std::free(val); std::free(sum); std::free(addStock); std::free(changeStock); std::free(changeFlag); } void init_sub(int node, int left, int right){ int sz = right - left, n1 = node*2+1, n2 = node*2+2; if(sz==1){ sum[node] = val[left]; addStock[node] = 0; changeFlag[node] = 0; } else { init_sub(n1, left, left+sz/2); init_sub(n2, left+sz/2, right); sum[node] = sum[n1] + sum[n2]; addStock[node] = 0; changeFlag[node] = 0; } } void init(int N, int zerofill = 0){ int i; size = N; if(zerofill) rep(i,N) val[i] = 0; init_sub(0, 0, N); } void lazyEval(int node, int left, int right){ int sz = right - left, n1 = node*2+1, n2 = node*2+2; if(sz==1) return; if(changeFlag[node]){ changeFlag[n1] = changeFlag[n2] = 1; changeStock[n1] = changeStock[n2] = changeStock[node] + addStock[node]; addStock[n1] = addStock[n2] = 0; sum[n1] = changeStock[n1] * (left+sz/2 - left); sum[n2] = changeStock[n2] * (right - (left+sz/2)); } else if(addStock[node]){ changeFlag[n1] = changeFlag[n2] = 0; addStock[n1] += addStock[node]; addStock[n2] += addStock[node]; sum[n1] += addStock[node] * (left+sz/2 - left); sum[n2] += addStock[node] * (right - (left+sz/2)); } addStock[node] = 0; changeFlag[node] = 0; } void change_sub(int node, int left, int right, int a, int b, T v){ int sz = right - left, n1 = node*2+1, n2 = node*2+2; a = max(a, left); b = min(b, right); if(a >= b) return; if(a==left && b==right){ changeFlag[node] = 1; changeStock[node] = v; addStock[node] = 0; sum[node] = v * (right - left); return; } if(addStock[node] || changeFlag[node]) lazyEval(node, left, right); change_sub(n1, left, left+sz/2, a, b, v); change_sub(n2, left+sz/2, right, a, b, v); sum[node] = sum[n1] + sum[n2]; } void change(int a, int b, T v){ change_sub(0, 0, size, a, b, v); } void add_sub(int node, int left, int right, int a, int b, T v){ int sz = right - left, n1 = node*2+1, n2 = node*2+2; a = max(a, left); b = min(b, right); if(a >= b) return; if(a==left && b==right){ addStock[node] += v; sum[node] += v * (right - left); return; } if(addStock[node] || changeFlag[node]) lazyEval(node, left, right); add_sub(n1, left, left+sz/2, a, b, v); add_sub(n2, left+sz/2, right, a, b, v); sum[node] = sum[n1] + sum[n2]; } void add(int a, int b, T v){ add_sub(0, 0, size, a, b, v); } T get_sum_sub(int node, int left, int right, int a, int b){ int sz = right - left, n1 = node*2+1, n2 = node*2+2; a = max(a, left); b = min(b, right); if(a >= b) return 0; if(a==left && b==right) return sum[node]; if(addStock[node] || changeFlag[node]) lazyEval(node, left, right); return get_sum_sub(n1,left,left+sz/2,a,b) + get_sum_sub(n2,left+sz/2,right,a,b); } T get_sum(int a, int b){ return get_sum_sub(0, 0, size, a, b); } }; int N, Q; int X, L, R; int main(){ int i, j, k, v1, v2; ll s1=0, s2=0; lazySegtreeSum<int> t1, t2; reader(&N,&Q); t1.malloc(N); t2.malloc(N); t1.init(N, 1); t2.init(N, 1); while(Q--){ reader(&X,&L,&R); R++; if(X==0){ v1 = t1.get_sum(L, R); v2 = t2.get_sum(L, R); if(v1 > v2) s1 += v1; if(v1 < v2) s2 += v2; } else if(X==1){ t1.change(L, R, 1); t2.change(L, R, 0); } else if(X==2){ t1.change(L, R, 0); t2.change(L, R, 1); } } s1 += t1.get_sum(0, N); s2 += t2.get_sum(0, N); writerLn(s1,s2); return 0; }