Submission #793712

# Submission time Handle Problem Language Result Execution time Memory
793712 2023-07-26T05:48:27 Z 이동현(#10060) Triangle Collection (CCO23_day2problem3) C++17
25 / 25
297 ms 29932 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

struct Seg{
    int n;
    vector<int> tr, mn;
    Seg(int m){
        n = m + 4;
        tr.resize(n * 4 + 4);
        mn.resize(n * 4 + 4);
    }

    void push(int x, int s, int e, int pos, int val){
        if(s == e){
            tr[x] += val;
            mn[x] = min(0ll, tr[x]);
            return;
        }

        int m = s + e >> 1;
        if(pos <= m){
            push(x * 2, s, m, pos, val);
        }
        else{
            push(x * 2 + 1, m + 1, e, pos, val);
        }

        tr[x] = tr[x * 2] + tr[x * 2 + 1];
        mn[x] = min(mn[x * 2], tr[x * 2] + mn[x * 2 + 1]);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    int bsum = 0;
    Seg tr(n * 2 + 4);
    for(int i = 0; i < n; ++i){
        if(a[i] % 2){
            tr.push(1, 0, n * 2, i, 1);
        }
        tr.push(1, 0, n * 2, i * 2, -(a[i] / 2));
        bsum += a[i] / 2;
    }

    while(q--){
        int x, y;
        cin >> x >> y;
        --x;

        if(a[x] % 2){
            tr.push(1, 0, n * 2, x, -1);
        }
        bsum -= a[x] / 2;
        tr.push(1, 0, n * 2, x * 2, (a[x] / 2));

        a[x] += y;
        
        if(a[x] % 2){
            tr.push(1, 0, n * 2, x, 1);
        }
        bsum += a[x] / 2;
        tr.push(1, 0, n * 2, x * 2, -(a[x] / 2));

        int ans = bsum;
        int rv = -tr.mn[1];
        if(rv > 0){
            ans -= (rv - 1) / 3 + 1;
        }

        cout << ans << '\n';
    }
    
    return 0;
}

Compilation message

Main.cpp: In member function 'void Seg::push(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         int m = s + e >> 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 480 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 44 ms 660 KB Output is correct
4 Correct 199 ms 28120 KB Output is correct
5 Correct 214 ms 28132 KB Output is correct
6 Correct 216 ms 28048 KB Output is correct
7 Correct 193 ms 28100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 214 ms 28280 KB Output is correct
6 Correct 224 ms 29924 KB Output is correct
7 Correct 223 ms 29928 KB Output is correct
8 Correct 244 ms 29888 KB Output is correct
9 Correct 220 ms 29900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 480 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 44 ms 660 KB Output is correct
32 Correct 199 ms 28120 KB Output is correct
33 Correct 214 ms 28132 KB Output is correct
34 Correct 216 ms 28048 KB Output is correct
35 Correct 193 ms 28100 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 214 ms 28280 KB Output is correct
41 Correct 224 ms 29924 KB Output is correct
42 Correct 223 ms 29928 KB Output is correct
43 Correct 244 ms 29888 KB Output is correct
44 Correct 220 ms 29900 KB Output is correct
45 Correct 248 ms 29932 KB Output is correct
46 Correct 242 ms 29828 KB Output is correct
47 Correct 247 ms 29864 KB Output is correct
48 Correct 222 ms 28284 KB Output is correct
49 Correct 149 ms 29924 KB Output is correct
50 Correct 217 ms 28604 KB Output is correct
51 Correct 281 ms 28580 KB Output is correct
52 Correct 218 ms 29876 KB Output is correct
53 Correct 297 ms 28100 KB Output is correct
54 Correct 195 ms 28092 KB Output is correct