Submission #711942

# Submission time Handle Problem Language Result Execution time Memory
711942 2023-03-17T17:37:13 Z kostia244 Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 4536 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int inf = 1'000'000'003;
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n;
    vector<int> a(n);
    for(auto &i : a) cin >> i;
 
    vector<int> die(n + 1);
    vector<array<int, 3>> useful;
    auto add = [&](int l, int r) {
        if(l < r) {
            die[l]++;
            die[r]--;
        }
    };
 
    auto scan = [&](vector<array<int, 3>> ind, int mode) {
        vector<array<ll, 3>> st;
        for(auto [i, ls, rs] : ind) {
            ll sum = ls;
            while(st.size() && a[st.back()[0]] < a[i]) {
                sum += st.back()[1];
                sum += a[st.back()[0]];
                st.pop_back();
            }
            if(sum < a[i]) {
                if(mode == 0) {//fwd
                    add(st.empty() ? ind[0][0] : st.back()[0] + 1, i);
                } else {
                    add(i + 1, st.empty() ? ind[0][0] + 1 : st.back()[0]);
                }
            }
            st.push_back({i, min<ll>(sum, inf)});
        }
    };
 
    cin >> q;
    for(int t, l, r, i = 0; i < q; i++) {
        cin >> t >> l >> r;
        --l;
        if(t == 1) {
            a[l] = r;
        } else {
            die.assign(n + 1, 0);
            useful.clear();
            for(int i = l; i < r; i++)
                useful.push_back({i, 0, 0});
            
            scan(useful, 0);
            reverse(all(useful));
            for(auto &[i, ls, rs] : useful)
                swap(ls, rs);
            scan(useful, 1);
            
 
            int ans = 0, cur = 0;
            for(int i = l; i < r; i++) {
                cur += die[i];
                ans += !cur;
            }
            cout << ans << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 9 ms 348 KB Output is correct
9 Correct 12 ms 340 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 11 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 11 ms 356 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 12 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 22 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 20 ms 3524 KB Output is correct
3 Correct 23 ms 3528 KB Output is correct
4 Correct 27 ms 3524 KB Output is correct
5 Correct 23 ms 3528 KB Output is correct
6 Correct 27 ms 3528 KB Output is correct
7 Correct 22 ms 3528 KB Output is correct
8 Correct 29 ms 3592 KB Output is correct
9 Correct 22 ms 3528 KB Output is correct
10 Correct 23 ms 3572 KB Output is correct
11 Correct 22 ms 3532 KB Output is correct
12 Correct 22 ms 3580 KB Output is correct
13 Correct 21 ms 3528 KB Output is correct
14 Correct 24 ms 3716 KB Output is correct
15 Correct 26 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 9 ms 348 KB Output is correct
9 Correct 12 ms 340 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 11 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 11 ms 356 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 12 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 22 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 20 ms 3524 KB Output is correct
23 Correct 23 ms 3528 KB Output is correct
24 Correct 27 ms 3524 KB Output is correct
25 Correct 23 ms 3528 KB Output is correct
26 Correct 27 ms 3528 KB Output is correct
27 Correct 22 ms 3528 KB Output is correct
28 Correct 29 ms 3592 KB Output is correct
29 Correct 22 ms 3528 KB Output is correct
30 Correct 23 ms 3572 KB Output is correct
31 Correct 22 ms 3532 KB Output is correct
32 Correct 22 ms 3580 KB Output is correct
33 Correct 21 ms 3528 KB Output is correct
34 Correct 24 ms 3716 KB Output is correct
35 Correct 26 ms 3712 KB Output is correct
36 Correct 1879 ms 3560 KB Output is correct
37 Correct 2928 ms 4100 KB Output is correct
38 Correct 3402 ms 4084 KB Output is correct
39 Correct 722 ms 4124 KB Output is correct
40 Correct 3508 ms 4428 KB Output is correct
41 Correct 2873 ms 4452 KB Output is correct
42 Correct 3609 ms 4264 KB Output is correct
43 Correct 2977 ms 4268 KB Output is correct
44 Correct 3444 ms 4428 KB Output is correct
45 Correct 1844 ms 4536 KB Output is correct
46 Correct 2426 ms 4232 KB Output is correct
47 Correct 3803 ms 3352 KB Output is correct
48 Correct 1010 ms 4164 KB Output is correct
49 Correct 3431 ms 4020 KB Output is correct
50 Correct 1962 ms 3940 KB Output is correct
51 Execution timed out 4049 ms 3920 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 20 ms 3524 KB Output is correct
3 Correct 23 ms 3528 KB Output is correct
4 Correct 27 ms 3524 KB Output is correct
5 Correct 23 ms 3528 KB Output is correct
6 Correct 27 ms 3528 KB Output is correct
7 Correct 22 ms 3528 KB Output is correct
8 Correct 29 ms 3592 KB Output is correct
9 Correct 22 ms 3528 KB Output is correct
10 Correct 23 ms 3572 KB Output is correct
11 Correct 22 ms 3532 KB Output is correct
12 Correct 22 ms 3580 KB Output is correct
13 Correct 21 ms 3528 KB Output is correct
14 Correct 24 ms 3716 KB Output is correct
15 Correct 26 ms 3712 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4042 ms 3964 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 20 ms 3524 KB Output is correct
3 Correct 23 ms 3528 KB Output is correct
4 Correct 27 ms 3524 KB Output is correct
5 Correct 23 ms 3528 KB Output is correct
6 Correct 27 ms 3528 KB Output is correct
7 Correct 22 ms 3528 KB Output is correct
8 Correct 29 ms 3592 KB Output is correct
9 Correct 22 ms 3528 KB Output is correct
10 Correct 23 ms 3572 KB Output is correct
11 Correct 22 ms 3532 KB Output is correct
12 Correct 22 ms 3580 KB Output is correct
13 Correct 21 ms 3528 KB Output is correct
14 Correct 24 ms 3716 KB Output is correct
15 Correct 26 ms 3712 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4046 ms 3660 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 232 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 9 ms 348 KB Output is correct
9 Correct 12 ms 340 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 11 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 11 ms 356 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 12 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 22 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 20 ms 3524 KB Output is correct
23 Correct 23 ms 3528 KB Output is correct
24 Correct 27 ms 3524 KB Output is correct
25 Correct 23 ms 3528 KB Output is correct
26 Correct 27 ms 3528 KB Output is correct
27 Correct 22 ms 3528 KB Output is correct
28 Correct 29 ms 3592 KB Output is correct
29 Correct 22 ms 3528 KB Output is correct
30 Correct 23 ms 3572 KB Output is correct
31 Correct 22 ms 3532 KB Output is correct
32 Correct 22 ms 3580 KB Output is correct
33 Correct 21 ms 3528 KB Output is correct
34 Correct 24 ms 3716 KB Output is correct
35 Correct 26 ms 3712 KB Output is correct
36 Correct 1879 ms 3560 KB Output is correct
37 Correct 2928 ms 4100 KB Output is correct
38 Correct 3402 ms 4084 KB Output is correct
39 Correct 722 ms 4124 KB Output is correct
40 Correct 3508 ms 4428 KB Output is correct
41 Correct 2873 ms 4452 KB Output is correct
42 Correct 3609 ms 4264 KB Output is correct
43 Correct 2977 ms 4268 KB Output is correct
44 Correct 3444 ms 4428 KB Output is correct
45 Correct 1844 ms 4536 KB Output is correct
46 Correct 2426 ms 4232 KB Output is correct
47 Correct 3803 ms 3352 KB Output is correct
48 Correct 1010 ms 4164 KB Output is correct
49 Correct 3431 ms 4020 KB Output is correct
50 Correct 1962 ms 3940 KB Output is correct
51 Execution timed out 4049 ms 3920 KB Time limit exceeded
52 Halted 0 ms 0 KB -