Submission #151755

# Submission time Handle Problem Language Result Execution time Memory
151755 2019-09-04T14:52:25 Z arnold518 None (KOI17_shell) C++14
0 / 100
287 ms 54080 KB
#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");

    A[y][x]+=val;
    bit[y].update(x, val);
    bit[y].update(x+1, -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)) break;
    }
    e=i;
    bit[y].update(x+1, val);
    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);
    }

    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

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:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
shell.cpp:73: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:83: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 time Memory Grader output
1 Incorrect 5 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 287 ms 54080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -