Submission #151757

#TimeUsernameProblemLanguageResultExecution timeMemory
151757arnold518조개 줍기 (KOI17_shell)C++14
100 / 100
618 ms62332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1500; int N; ll A[MAXN+10][MAXN+10], B[MAXN+10][MAXN+10], ans; struct BIT { ll tree[MAXN+10]; void update(int i, ll val) { for(; i<=N; i+=(i&-i)) tree[i]+=val; } ll query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; } }; BIT bit[MAXN+10]; ll query(int y, int x, int val) { int i, j; int s=x, e=x; //printf("=========\n"); //for(i=1; i<=N; i++) { for(j=1; j<=N; j++) printf("%d ", bit[i].query(j)); printf("\n"); } //printf("=========\n"); bit[y].update(x, val); for(i=x+1; i<=N; i++) { ll t=max(bit[y].query(i-1), bit[y-1].query(i))+A[y][i]; if(t==bit[y].query(i)-val) break; } e=i; bit[y].update(e, -val); ans+=val*(e-s); //printf("!%d %d\n", s, e); for(i=y+1; i<=N; i++) { while(s<e) { ll t=max(bit[i].query(s-1), bit[i-1].query(s))+A[i][s]; if(t!=bit[i].query(s)) break; s++; } bit[i].update(s, val); while(e<=N) { ll t=max(bit[i].query(e-1), bit[i-1].query(e))+A[i][e]; if(t==bit[i].query(e)-val) break; e++; } bit[i].update(e, -val); ans+=val*(e-s); //printf("!%d %d\n", s, e); if(s==e) break; } A[y][x]+=val; return ans; } int main() { int i, j; scanf("%d", &N); for(i=1; i<=N; i++) for(j=1; j<=N; j++) scanf("%lld", &A[i][j]); for(i=1; i<=N; i++) for(j=1; j<=N; j++) B[i][j]=A[i][j]+max(B[i-1][j], B[i][j-1]); for(i=1; i<=N; i++) for(j=1; j<=N; j++) ans+=B[i][j]; printf("%lld\n", ans); for(i=1; i<=N; i++) for(j=1; j<=N; j++) bit[i].update(j, B[i][j]-B[i][j-1]); for(i=1; i<=N; i++) { char t; int y, x; scanf("\n%c%d%d", &t, &y, &x); if(t=='U') printf("%lld\n", query(y, x, 1)); else printf("%lld\n", query(y, x, -1)); } }

Compilation message (stderr)

shell.cpp: In function 'll query(int, int, int)':
shell.cpp:23:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
shell.cpp: In function 'int main()':
shell.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
shell.cpp:72:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) for(j=1; j<=N; j++) scanf("%lld", &A[i][j]);
                                             ~~~~~^~~~~~~~~~~~~~~~~~
shell.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n%c%d%d", &t, &y, &x);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...