Submission #711940

# Submission time Handle Problem Language Result Execution time Memory
711940 2023-03-17T17:34:51 Z kostia244 Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 4544 KB
#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;
    
    auto get_sum = [&](int a, int b) {
        return min(a + b, inf);
    };
 
    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) {
            int sum = ls;
            while(st.size() && a[st.back()[0]] < a[i]) {
                sum = get_sum(sum, get_sum(st.back()[1], 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, sum});
        }
    };
 
    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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 352 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 5 ms 360 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 8 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3528 KB Output is correct
3 Correct 12 ms 3528 KB Output is correct
4 Correct 17 ms 3524 KB Output is correct
5 Correct 13 ms 3568 KB Output is correct
6 Correct 16 ms 3524 KB Output is correct
7 Correct 14 ms 3528 KB Output is correct
8 Correct 17 ms 3536 KB Output is correct
9 Correct 13 ms 3528 KB Output is correct
10 Correct 14 ms 3532 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 12 ms 3528 KB Output is correct
14 Correct 14 ms 3784 KB Output is correct
15 Correct 14 ms 3764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 352 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 5 ms 360 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 8 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 14 ms 3528 KB Output is correct
23 Correct 12 ms 3528 KB Output is correct
24 Correct 17 ms 3524 KB Output is correct
25 Correct 13 ms 3568 KB Output is correct
26 Correct 16 ms 3524 KB Output is correct
27 Correct 14 ms 3528 KB Output is correct
28 Correct 17 ms 3536 KB Output is correct
29 Correct 13 ms 3528 KB Output is correct
30 Correct 14 ms 3532 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3528 KB Output is correct
33 Correct 12 ms 3528 KB Output is correct
34 Correct 14 ms 3784 KB Output is correct
35 Correct 14 ms 3764 KB Output is correct
36 Correct 687 ms 3692 KB Output is correct
37 Correct 1089 ms 4100 KB Output is correct
38 Correct 1258 ms 4152 KB Output is correct
39 Correct 275 ms 4072 KB Output is correct
40 Correct 1408 ms 4420 KB Output is correct
41 Correct 1165 ms 4452 KB Output is correct
42 Correct 1587 ms 4268 KB Output is correct
43 Correct 1329 ms 4264 KB Output is correct
44 Correct 1626 ms 4428 KB Output is correct
45 Correct 749 ms 4544 KB Output is correct
46 Correct 1027 ms 4236 KB Output is correct
47 Correct 1554 ms 3444 KB Output is correct
48 Correct 474 ms 4080 KB Output is correct
49 Correct 1584 ms 4036 KB Output is correct
50 Correct 776 ms 3948 KB Output is correct
51 Correct 3144 ms 3896 KB Output is correct
52 Correct 3744 ms 3716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3528 KB Output is correct
3 Correct 12 ms 3528 KB Output is correct
4 Correct 17 ms 3524 KB Output is correct
5 Correct 13 ms 3568 KB Output is correct
6 Correct 16 ms 3524 KB Output is correct
7 Correct 14 ms 3528 KB Output is correct
8 Correct 17 ms 3536 KB Output is correct
9 Correct 13 ms 3528 KB Output is correct
10 Correct 14 ms 3532 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 12 ms 3528 KB Output is correct
14 Correct 14 ms 3784 KB Output is correct
15 Correct 14 ms 3764 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4066 ms 3984 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3528 KB Output is correct
3 Correct 12 ms 3528 KB Output is correct
4 Correct 17 ms 3524 KB Output is correct
5 Correct 13 ms 3568 KB Output is correct
6 Correct 16 ms 3524 KB Output is correct
7 Correct 14 ms 3528 KB Output is correct
8 Correct 17 ms 3536 KB Output is correct
9 Correct 13 ms 3528 KB Output is correct
10 Correct 14 ms 3532 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 12 ms 3528 KB Output is correct
14 Correct 14 ms 3784 KB Output is correct
15 Correct 14 ms 3764 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4078 ms 3528 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 352 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 5 ms 360 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 8 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 14 ms 3528 KB Output is correct
23 Correct 12 ms 3528 KB Output is correct
24 Correct 17 ms 3524 KB Output is correct
25 Correct 13 ms 3568 KB Output is correct
26 Correct 16 ms 3524 KB Output is correct
27 Correct 14 ms 3528 KB Output is correct
28 Correct 17 ms 3536 KB Output is correct
29 Correct 13 ms 3528 KB Output is correct
30 Correct 14 ms 3532 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3528 KB Output is correct
33 Correct 12 ms 3528 KB Output is correct
34 Correct 14 ms 3784 KB Output is correct
35 Correct 14 ms 3764 KB Output is correct
36 Correct 687 ms 3692 KB Output is correct
37 Correct 1089 ms 4100 KB Output is correct
38 Correct 1258 ms 4152 KB Output is correct
39 Correct 275 ms 4072 KB Output is correct
40 Correct 1408 ms 4420 KB Output is correct
41 Correct 1165 ms 4452 KB Output is correct
42 Correct 1587 ms 4268 KB Output is correct
43 Correct 1329 ms 4264 KB Output is correct
44 Correct 1626 ms 4428 KB Output is correct
45 Correct 749 ms 4544 KB Output is correct
46 Correct 1027 ms 4236 KB Output is correct
47 Correct 1554 ms 3444 KB Output is correct
48 Correct 474 ms 4080 KB Output is correct
49 Correct 1584 ms 4036 KB Output is correct
50 Correct 776 ms 3948 KB Output is correct
51 Correct 3144 ms 3896 KB Output is correct
52 Correct 3744 ms 3716 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Execution timed out 4066 ms 3984 KB Time limit exceeded
55 Halted 0 ms 0 KB -