Submission #124490

# Submission time Handle Problem Language Result Execution time Memory
124490 2019-07-03T12:10:28 Z DJ035 None (KOI17_shell) C++14
100 / 100
487 ms 35660 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mx = 1505;

ll dpval = 0;
struct RRBIT{
    int n;
    ll *d;
    int *f;
    RRBIT(){}
    RRBIT(int n, ll *p, int *B):n(n),d(p),f(B){}
    
    void upd(int a, int b, int v){
        dpval += v * (b-a+1);
        for(;a<=n;a+=(a&-a)) f[a] += v;
        for(++b;b<=n;b+=(b&-b)) f[b] -= v;
    }
    ll gsum(int i){
        ll s = d[i];
        for(;i;i-=(i&-i)) s += f[i];
        return s;
    }
} I[mx];

ll dp[mx][mx], sh;
int BIT[mx][mx];

inline int t(int i, int j){
    return I[i].gsum(j);
}

int n;
int s[mx], e[mx];

void input(){
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin >> sh;
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + sh;
            dpval += dp[i][j];
        }
        I[i] = RRBIT(n, dp[i], BIT[i]);
    }
    cout << dpval << '\n';
}

void query(){
    char c;
    for(int i=1,x,y;i<=n;i++){
        cin >> c >> x >> y;
        c = (c == 'U');
        s[x] = y; e[x] = y + 1;
        int &sx = s[x], &ex = e[x];
        for(;ex <= n; ex++){
            if(x==1) continue;
            if( t(x, ex-1) + c <= t(x-1, ex) ) break;
            //if(c ? t(x,ex-1) < t(x-1,ex) : t(x,ex-1) <= t(x-1,ex)) break;
        }
        for(int j = x+1; j<=n; ++j){
            int &sj = s[j], &ej = e[j];
            sj = s[j-1]; ej = e[j-1];

            for(;1 < sj && sj < ej; sj++){
                
                if( t(j, sj-1) + !c <= t(j-1, sj) ) break;
                //if(c ? t(j,sj-1) <= t(j-1,sj) : t(j,sj-1) < t(j-1,sj)) break;

            }
            if(sj >= ej) break;

            for(;ej <= n; ej++){
                
                if( t(j, ej-1) + c <= t(j-1, ej) ) break;
                //if(c ? t(j,ej-1) < t(j-1,ej) : t(j,ej-1) <= t(j-1,ej)) break;
            }        
        }
        for(int j=x;j<=n;j++){
            if(s[j] >= e[j]) break;
            I[j].upd(s[j], e[j]-1, 2*c-1);
        }
        cout << dpval << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    input();
    query();
}

Compilation message

shell.cpp: In function 'void query()':
shell.cpp:56:14: warning: unused variable 'sx' [-Wunused-variable]
         int &sx = s[x], &ex = e[x];
              ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1400 KB Output is correct
2 Correct 4 ms 1400 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 4 ms 1400 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 4 ms 1272 KB Output is correct
8 Correct 4 ms 1272 KB Output is correct
9 Correct 4 ms 1272 KB Output is correct
10 Correct 4 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 24692 KB Output is correct
2 Correct 164 ms 24704 KB Output is correct
3 Correct 175 ms 31268 KB Output is correct
4 Correct 157 ms 23544 KB Output is correct
5 Correct 164 ms 23732 KB Output is correct
6 Correct 164 ms 24696 KB Output is correct
7 Correct 163 ms 24696 KB Output is correct
8 Correct 157 ms 23620 KB Output is correct
9 Correct 157 ms 23632 KB Output is correct
10 Correct 158 ms 23664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1400 KB Output is correct
2 Correct 4 ms 1400 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 4 ms 1400 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 4 ms 1272 KB Output is correct
8 Correct 4 ms 1272 KB Output is correct
9 Correct 4 ms 1272 KB Output is correct
10 Correct 169 ms 24692 KB Output is correct
11 Correct 164 ms 24704 KB Output is correct
12 Correct 175 ms 31268 KB Output is correct
13 Correct 157 ms 23544 KB Output is correct
14 Correct 164 ms 23732 KB Output is correct
15 Correct 164 ms 24696 KB Output is correct
16 Correct 163 ms 24696 KB Output is correct
17 Correct 157 ms 23620 KB Output is correct
18 Correct 157 ms 23632 KB Output is correct
19 Correct 158 ms 23664 KB Output is correct
20 Correct 223 ms 35576 KB Output is correct
21 Correct 233 ms 35504 KB Output is correct
22 Correct 251 ms 35548 KB Output is correct
23 Correct 482 ms 35564 KB Output is correct
24 Correct 435 ms 35512 KB Output is correct
25 Correct 461 ms 35576 KB Output is correct
26 Correct 164 ms 24696 KB Output is correct
27 Correct 171 ms 31380 KB Output is correct
28 Correct 219 ms 35576 KB Output is correct
29 Correct 221 ms 35612 KB Output is correct
30 Correct 431 ms 35448 KB Output is correct
31 Correct 487 ms 35660 KB Output is correct
32 Correct 162 ms 24696 KB Output is correct
33 Correct 156 ms 23676 KB Output is correct
34 Correct 4 ms 1272 KB Output is correct