Submission #404415

# Submission time Handle Problem Language Result Execution time Memory
404415 2021-05-14T11:41:22 Z joelau None (KOI17_shell) C++14
100 / 100
724 ms 35396 KB
#include <bits/stdc++.h>
using namespace std;

int N, A[1500][1500];
long long ft[1500][1501];

void update (int n, int x, long long v) {
    x++;
    while (x <= N) ft[n][x] += v, x += x & -x;
}

void update (int n, int a, int b, long long v) {
    update(n,a,v); update(n,b+1,-v);
}

long long query (int n, int x) {
    x++;
    long long ans = 0;
    while (x) ans += ft[n][x], x -= x & -x;
    return ans;
}

long long f(int x, int y) {
    long long ans = 0;
    if (x != 0) ans = max(ans,query(x-1,y));
    if (y != 0) ans = max(ans,query(x,y-1));
    return ans + A[x][y];
}

int main() {
    scanf("%d", &N);
    memset(ft,0,sizeof(ft));
    long long ans = 0;
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
        scanf("%d", &A[i][j]);
        long long val = f(i,j);
        update(i,j,j,val);
        ans += val;
    }
    printf("%lld\n", ans);
    for (int a = 0; a < N; ++a) {
        char c; int x,y; scanf(" %c %d %d", &c, &x, &y); x--, y--;
        int v = c == 'U' ? 1 : -1, s = y, e = y+1;
        A[x][y] += v, ans += v;
        update(x,s,s,v);
        while (e < N && f(x,e) != query(x,e)) update(x,e,e,v), e++, ans += v;
        for (int i = x+1; i < N; ++i) {
            while (s < e && f(i,s) == query(i,s)) s++;
            update(i,s,e-1,v), ans += (e-s) * v;
            while (e < N && f(i,e) != query(i,e)) update(i,e,e,v), e++, ans += v;
        }
        printf("%lld\n", ans);
    }

    return 0;
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
shell.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d", &A[i][j]);
      |         ~~~~~^~~~~~~~~~~~~~~~
shell.cpp:42:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         char c; int x,y; scanf(" %c %d %d", &c, &x, &y); x--, y--;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18300 KB Output is correct
2 Correct 12 ms 18332 KB Output is correct
3 Correct 12 ms 18380 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 12 ms 18380 KB Output is correct
6 Correct 12 ms 18400 KB Output is correct
7 Correct 12 ms 18380 KB Output is correct
8 Correct 12 ms 18296 KB Output is correct
9 Correct 11 ms 18380 KB Output is correct
10 Correct 11 ms 18380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 31164 KB Output is correct
2 Correct 360 ms 31152 KB Output is correct
3 Correct 448 ms 31124 KB Output is correct
4 Correct 534 ms 31112 KB Output is correct
5 Correct 514 ms 31112 KB Output is correct
6 Correct 359 ms 31044 KB Output is correct
7 Correct 359 ms 31300 KB Output is correct
8 Correct 527 ms 31044 KB Output is correct
9 Correct 518 ms 31008 KB Output is correct
10 Correct 492 ms 31048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18300 KB Output is correct
2 Correct 12 ms 18332 KB Output is correct
3 Correct 12 ms 18380 KB Output is correct
4 Correct 12 ms 18396 KB Output is correct
5 Correct 12 ms 18380 KB Output is correct
6 Correct 12 ms 18400 KB Output is correct
7 Correct 12 ms 18380 KB Output is correct
8 Correct 12 ms 18296 KB Output is correct
9 Correct 11 ms 18380 KB Output is correct
10 Correct 355 ms 31164 KB Output is correct
11 Correct 360 ms 31152 KB Output is correct
12 Correct 448 ms 31124 KB Output is correct
13 Correct 534 ms 31112 KB Output is correct
14 Correct 514 ms 31112 KB Output is correct
15 Correct 359 ms 31044 KB Output is correct
16 Correct 359 ms 31300 KB Output is correct
17 Correct 527 ms 31044 KB Output is correct
18 Correct 518 ms 31008 KB Output is correct
19 Correct 492 ms 31048 KB Output is correct
20 Correct 11 ms 18380 KB Output is correct
21 Correct 513 ms 35280 KB Output is correct
22 Correct 526 ms 35252 KB Output is correct
23 Correct 538 ms 35268 KB Output is correct
24 Correct 698 ms 35396 KB Output is correct
25 Correct 663 ms 34688 KB Output is correct
26 Correct 689 ms 34876 KB Output is correct
27 Correct 356 ms 31168 KB Output is correct
28 Correct 432 ms 31016 KB Output is correct
29 Correct 526 ms 34316 KB Output is correct
30 Correct 529 ms 33988 KB Output is correct
31 Correct 672 ms 33916 KB Output is correct
32 Correct 724 ms 34000 KB Output is correct
33 Correct 359 ms 31132 KB Output is correct
34 Correct 494 ms 31064 KB Output is correct