Submission #366856

#TimeUsernameProblemLanguageResultExecution timeMemory
366856leinad2조개 줍기 (KOI17_shell)C++17
0 / 100
2092 ms126316 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int n, i, j, k, a, b, B[1510][1510], ans; char c; struct tree { int seg[6010], lazy[6010]; void busy(int id, int s, int e, int m) { seg[id*2]+=(m-s+1)*lazy[id]; seg[id*2+1]+=(e-m)*lazy[id]; lazy[id*2]+=lazy[id]; lazy[id*2+1]+=lazy[id]; lazy[id]=0; } void update(int id, int s, int e, int l, int r, int v) { if(l>r)return; if(e<l||r<s)return; if(l<=s&&e<=r) { seg[id]+=(e-s+1)*v; lazy[id]+=v; return; } int m=s+e>>1; busy(id, s, e, m); update(id*2, s, m, l, r, v); update(id*2+1, m+1, e, l, r, v); seg[id]=seg[id*2]+seg[id*2+1]; } int get(int id, int s, int e, int l, int r) { if(e<l||r<s)return 0; if(l<=s&&e<=r)return seg[id]; int m=s+e>>1; busy(id, s, e, m); return get(id*2, s, m, l, r)+get(id*2+1, m+1, e, l, r); } }A[1510]; main() { ios_base::sync_with_stdio(!cin.tie(NULL)); cout.tie(NULL); for(cin>>n;i++<n;) { for(j=0;j++<n;) { cin>>a; B[i][j]=max(B[i][j-1], B[i-1][j])+a; A[i].update(1, 1, n, j, j, B[i][j]); } } for(i=0;i++<n;)ans+=A[i].get(1, 1, n, 1, n); cout<<ans<<"\n"; for(int q=0;q++<n;) { cin>>c>>a>>b; int pt1=b, pt2=b+1; if(c=='U') { while(pt2<=n) { if(A[a-1].get(1, 1, n, pt2, pt2)<=A[a].get(1, 1, n, pt2-1, pt2-1))pt2++; else break; } pt2--; ans+=(pt2-pt1+1); A[a].update(1, 1, n, pt1, pt2, 1); } else { while(pt2<=n) { if(A[a-1].get(1, 1, n, pt2, pt2)<A[a].get(1, 1, n, pt2-1, pt2-1))pt2++; else break; } pt2--; ans-=(pt2-pt1+1); A[a].update(1, 1, n, pt1, pt2, -1); } //printf("%lld %lld\n", pt1, pt2); for(i=a;i++<n;) { if(c=='U') { while(pt1<=n) { if(A[i-1].get(1, 1, n, pt1, pt1)>A[i].get(1, 1, n, pt1-1, pt1-1))break; else pt1++; } pt2++; while(pt2<=n) { if(A[i-1].get(1, 1, n, pt2, pt2)>A[i].get(1, 1, n, pt2-1, pt2-1))pt2++; else break; } pt2--; ans+=(pt2-pt1+1); A[i].update(1, 1, n, pt1, pt2, 1); } else { while(pt1<=n) { if(A[i-1].get(1, 1, n, pt1, pt1)>=A[i].get(1, 1, n, pt1-1, pt1-1))break; else pt1++; } pt2++; while(pt2<=n) { if(A[i-1].get(1, 1, n, pt2, pt2)>=A[i].get(1, 1, n, pt2-1, pt2-1))pt2++; else break; } pt2--; ans-=(pt2-pt1+1); A[i].update(1, 1, n, pt1, pt2, -1); } //printf("%lld %lld\n", pt1, pt2); } int ans2=0; for(i=0;i++<n;)ans2+=A[i].get(1, 1, n, 1, n);if(ans!=ans2)for(;;); cout<<ans<<"\n"; } }

Compilation message (stderr)

shell.cpp: In member function 'void tree::update(long long int, long long int, long long int, long long int, long long int, long long int)':
shell.cpp:27:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |         int m=s+e>>1;
      |               ~^~
shell.cpp: In member function 'long long int tree::get(long long int, long long int, long long int, long long int, long long int)':
shell.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |         int m=s+e>>1;
      |               ~^~
shell.cpp: At global scope:
shell.cpp:42:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main()
      |      ^
shell.cpp: In function 'int main()':
shell.cpp:123:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  123 |       for(i=0;i++<n;)ans2+=A[i].get(1, 1, n, 1, n);if(ans!=ans2)for(;;);
      |       ^~~
shell.cpp:123:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  123 |       for(i=0;i++<n;)ans2+=A[i].get(1, 1, n, 1, n);if(ans!=ans2)for(;;);
      |                                                    ^~
shell.cpp:123:65: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  123 |       for(i=0;i++<n;)ans2+=A[i].get(1, 1, n, 1, n);if(ans!=ans2)for(;;);
      |                                                                 ^~~
shell.cpp:124:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  124 |         cout<<ans<<"\n";
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...