Submission #711939

# Submission time Handle Problem Language Result Execution time Memory
711939 2023-03-17T17:33:54 Z kostia244 Fish 2 (JOI22_fish2) C++17
8 / 100
16 ms 3764 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);
    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});
        }
    };
 
            vector<array<int, 3>> useful;
    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);
            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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 3528 KB Output is correct
3 Correct 13 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3532 KB Output is correct
6 Correct 16 ms 3528 KB Output is correct
7 Correct 12 ms 3528 KB Output is correct
8 Correct 16 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3524 KB Output is correct
12 Correct 14 ms 3572 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 16 ms 3724 KB Output is correct
15 Correct 15 ms 3764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 3528 KB Output is correct
3 Correct 13 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3532 KB Output is correct
6 Correct 16 ms 3528 KB Output is correct
7 Correct 12 ms 3528 KB Output is correct
8 Correct 16 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3524 KB Output is correct
12 Correct 14 ms 3572 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 16 ms 3724 KB Output is correct
15 Correct 15 ms 3764 KB Output is correct
16 Incorrect 0 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 3528 KB Output is correct
3 Correct 13 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3532 KB Output is correct
6 Correct 16 ms 3528 KB Output is correct
7 Correct 12 ms 3528 KB Output is correct
8 Correct 16 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3524 KB Output is correct
12 Correct 14 ms 3572 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 16 ms 3724 KB Output is correct
15 Correct 15 ms 3764 KB Output is correct
16 Incorrect 1 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -