This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll dp[1600][1600], seg[1600][6000], input[1600][1600],ans,n, si=1;
ll query(ll x, ll y)
{
ll ret=0;
y=y+si-1;
while(y)
{
ret+=seg[x][y];
y/=2;
}
return ret;
}
void gang(ll x, ll v, ll l, ll r, ll s, ll e, ll t)
{
if(l>r||e<l||r<s||s>e)
return ;
if(s<=l&&r<=e)
{
seg[x][v]+=t;
return ;
}
gang(x,v*2,l,(l+r)/2,s,e,t);
gang(x,v*2+1,((l+r)/2)+1,r,s,e,t);
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll i, j,k,inx,iny,s,e,d;
char ina;
scanf("%lld", &n);
while(si<n)
si*=2;
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
scanf("%lld", &input[i][j]);
dp[i][j]=max(dp[i-1][j],dp[i][j-1])+input[i][j];
ans=ans+dp[i][j];
}
}
printf("%lld\n", ans);
for(k=1; k<=n; k++)
{
scanf(" %c %lld %lld",&ina,&inx,&iny);
if(ina=='U')
{
s=iny;
e=iny+1;
while(e<=n&&dp[inx-1][e]+query(inx-1,e)<=dp[inx][e-1]+query(inx,e-1)) e++;
gang(inx,1,1,si,s,e-1,1);
ans=ans+(e-s);
for(i=inx+1; i<=n&&s<e; i++)
{
while(s<e&&dp[i-1][s]+query(i-1,s)<=dp[i][s-1]+query(i,s-1))s++;
while(s<e&&e<=n&&dp[i-1][e]+query(i-1,e)<=dp[i][e-1]+query(i,e-1)) e++;
gang(i,1,1,si,s,e-1,1);
ans=ans+(e-s);
}
}
else
{
s=iny;
e=iny+1;
while(e<=n&&dp[inx-1][e]+query(inx-1,e)<dp[inx][e-1]+query(inx,e-1)) e++;
gang(inx,1,1,si,s,e-1,-1);
ans=ans-(e-s);
for(i=inx+1; i<=n&&s<e; i++)
{
while(s<e&&dp[i-1][s]+query(i-1,s)<dp[i][s-1]+query(i,s-1))s++;
while(s<e&&e<=n&&dp[i-1][e]+query(i-1,e)<dp[i][e-1]+query(i,e-1)) e++;
gang(i,1,1,si,s,e-1,-1);
ans=ans-(e-s);
}
}
printf("%lld\n", ans);
}
}
Compilation message (stderr)
shell.cpp: In function 'int main()':
shell.cpp:33:27: warning: unused variable 'd' [-Wunused-variable]
ll i, j,k,inx,iny,s,e,d;
^
shell.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
shell.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &input[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
shell.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c %lld %lld",&ina,&inx,&iny);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |