Submission #55983

# Submission time Handle Problem Language Result Execution time Memory
55983 2018-07-09T09:12:22 Z red1108 None (KOI17_shell) C++17
100 / 100
1687 ms 83216 KB
#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

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
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 2024 KB Output is correct
3 Correct 7 ms 2024 KB Output is correct
4 Correct 7 ms 2052 KB Output is correct
5 Correct 7 ms 2124 KB Output is correct
6 Correct 9 ms 2240 KB Output is correct
7 Correct 6 ms 2408 KB Output is correct
8 Correct 6 ms 2408 KB Output is correct
9 Correct 6 ms 2408 KB Output is correct
10 Correct 7 ms 2408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 314 ms 47688 KB Output is correct
2 Correct 399 ms 47688 KB Output is correct
3 Correct 434 ms 64780 KB Output is correct
4 Correct 416 ms 64780 KB Output is correct
5 Correct 412 ms 64780 KB Output is correct
6 Correct 415 ms 64780 KB Output is correct
7 Correct 322 ms 64780 KB Output is correct
8 Correct 315 ms 64780 KB Output is correct
9 Correct 331 ms 64780 KB Output is correct
10 Correct 332 ms 64780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 2024 KB Output is correct
3 Correct 7 ms 2024 KB Output is correct
4 Correct 7 ms 2052 KB Output is correct
5 Correct 7 ms 2124 KB Output is correct
6 Correct 9 ms 2240 KB Output is correct
7 Correct 6 ms 2408 KB Output is correct
8 Correct 6 ms 2408 KB Output is correct
9 Correct 6 ms 2408 KB Output is correct
10 Correct 314 ms 47688 KB Output is correct
11 Correct 399 ms 47688 KB Output is correct
12 Correct 434 ms 64780 KB Output is correct
13 Correct 416 ms 64780 KB Output is correct
14 Correct 412 ms 64780 KB Output is correct
15 Correct 415 ms 64780 KB Output is correct
16 Correct 322 ms 64780 KB Output is correct
17 Correct 315 ms 64780 KB Output is correct
18 Correct 331 ms 64780 KB Output is correct
19 Correct 332 ms 64780 KB Output is correct
20 Correct 467 ms 82868 KB Output is correct
21 Correct 506 ms 83216 KB Output is correct
22 Correct 504 ms 83216 KB Output is correct
23 Correct 1687 ms 83216 KB Output is correct
24 Correct 1573 ms 83216 KB Output is correct
25 Correct 1464 ms 83216 KB Output is correct
26 Correct 306 ms 83216 KB Output is correct
27 Correct 355 ms 83216 KB Output is correct
28 Correct 465 ms 83216 KB Output is correct
29 Correct 403 ms 83216 KB Output is correct
30 Correct 1268 ms 83216 KB Output is correct
31 Correct 1249 ms 83216 KB Output is correct
32 Correct 264 ms 83216 KB Output is correct
33 Correct 224 ms 83216 KB Output is correct
34 Correct 7 ms 2408 KB Output is correct