답안 #711938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711938 2023-03-17T17:31:11 Z kostia244 Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 4124 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});
        }
    };

    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);
            vector<array<int, 3>> useful;
            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';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 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 2 ms 340 KB Output is correct
20 Correct 8 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 18 ms 3524 KB Output is correct
3 Correct 14 ms 3528 KB Output is correct
4 Correct 19 ms 3528 KB Output is correct
5 Correct 14 ms 3528 KB Output is correct
6 Correct 22 ms 3532 KB Output is correct
7 Correct 12 ms 3520 KB Output is correct
8 Correct 20 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 15 ms 3524 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 13 ms 3528 KB Output is correct
14 Correct 14 ms 3736 KB Output is correct
15 Correct 15 ms 3760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 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 2 ms 340 KB Output is correct
20 Correct 8 ms 336 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 18 ms 3524 KB Output is correct
23 Correct 14 ms 3528 KB Output is correct
24 Correct 19 ms 3528 KB Output is correct
25 Correct 14 ms 3528 KB Output is correct
26 Correct 22 ms 3532 KB Output is correct
27 Correct 12 ms 3520 KB Output is correct
28 Correct 20 ms 3528 KB Output is correct
29 Correct 12 ms 3528 KB Output is correct
30 Correct 15 ms 3524 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3528 KB Output is correct
33 Correct 13 ms 3528 KB Output is correct
34 Correct 14 ms 3736 KB Output is correct
35 Correct 15 ms 3760 KB Output is correct
36 Correct 809 ms 3820 KB Output is correct
37 Correct 1237 ms 3736 KB Output is correct
38 Correct 1393 ms 3776 KB Output is correct
39 Correct 301 ms 3612 KB Output is correct
40 Correct 1512 ms 3816 KB Output is correct
41 Correct 1313 ms 3876 KB Output is correct
42 Correct 1682 ms 3828 KB Output is correct
43 Correct 1468 ms 3828 KB Output is correct
44 Correct 1700 ms 3888 KB Output is correct
45 Correct 811 ms 3796 KB Output is correct
46 Correct 1145 ms 3860 KB Output is correct
47 Correct 1769 ms 3852 KB Output is correct
48 Correct 491 ms 3728 KB Output is correct
49 Correct 1663 ms 3736 KB Output is correct
50 Correct 843 ms 3736 KB Output is correct
51 Correct 3808 ms 4056 KB Output is correct
52 Execution timed out 4075 ms 4124 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 18 ms 3524 KB Output is correct
3 Correct 14 ms 3528 KB Output is correct
4 Correct 19 ms 3528 KB Output is correct
5 Correct 14 ms 3528 KB Output is correct
6 Correct 22 ms 3532 KB Output is correct
7 Correct 12 ms 3520 KB Output is correct
8 Correct 20 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 15 ms 3524 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 13 ms 3528 KB Output is correct
14 Correct 14 ms 3736 KB Output is correct
15 Correct 15 ms 3760 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4061 ms 3924 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 18 ms 3524 KB Output is correct
3 Correct 14 ms 3528 KB Output is correct
4 Correct 19 ms 3528 KB Output is correct
5 Correct 14 ms 3528 KB Output is correct
6 Correct 22 ms 3532 KB Output is correct
7 Correct 12 ms 3520 KB Output is correct
8 Correct 20 ms 3528 KB Output is correct
9 Correct 12 ms 3528 KB Output is correct
10 Correct 15 ms 3524 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3528 KB Output is correct
13 Correct 13 ms 3528 KB Output is correct
14 Correct 14 ms 3736 KB Output is correct
15 Correct 15 ms 3760 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4067 ms 3968 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 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 2 ms 340 KB Output is correct
20 Correct 8 ms 336 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 18 ms 3524 KB Output is correct
23 Correct 14 ms 3528 KB Output is correct
24 Correct 19 ms 3528 KB Output is correct
25 Correct 14 ms 3528 KB Output is correct
26 Correct 22 ms 3532 KB Output is correct
27 Correct 12 ms 3520 KB Output is correct
28 Correct 20 ms 3528 KB Output is correct
29 Correct 12 ms 3528 KB Output is correct
30 Correct 15 ms 3524 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3528 KB Output is correct
33 Correct 13 ms 3528 KB Output is correct
34 Correct 14 ms 3736 KB Output is correct
35 Correct 15 ms 3760 KB Output is correct
36 Correct 809 ms 3820 KB Output is correct
37 Correct 1237 ms 3736 KB Output is correct
38 Correct 1393 ms 3776 KB Output is correct
39 Correct 301 ms 3612 KB Output is correct
40 Correct 1512 ms 3816 KB Output is correct
41 Correct 1313 ms 3876 KB Output is correct
42 Correct 1682 ms 3828 KB Output is correct
43 Correct 1468 ms 3828 KB Output is correct
44 Correct 1700 ms 3888 KB Output is correct
45 Correct 811 ms 3796 KB Output is correct
46 Correct 1145 ms 3860 KB Output is correct
47 Correct 1769 ms 3852 KB Output is correct
48 Correct 491 ms 3728 KB Output is correct
49 Correct 1663 ms 3736 KB Output is correct
50 Correct 843 ms 3736 KB Output is correct
51 Correct 3808 ms 4056 KB Output is correct
52 Execution timed out 4075 ms 4124 KB Time limit exceeded
53 Halted 0 ms 0 KB -