답안 #711943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711943 2023-03-17T17:39:20 Z kostia244 Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 4452 KB
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("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;
    
    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 {
            useful.clear();
            for(int i = l; i < r; i++)
                die[i] = 0, 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 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 340 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 364 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 340 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 5 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 9 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 3668 KB Output is correct
3 Correct 18 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3528 KB Output is correct
6 Correct 17 ms 3528 KB Output is correct
7 Correct 13 ms 3528 KB Output is correct
8 Correct 18 ms 3528 KB Output is correct
9 Correct 14 ms 3656 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3524 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 14 ms 3732 KB Output is correct
15 Correct 16 ms 3744 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 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 340 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 364 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 340 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 5 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 9 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 16 ms 3668 KB Output is correct
23 Correct 18 ms 3528 KB Output is correct
24 Correct 14 ms 3528 KB Output is correct
25 Correct 13 ms 3528 KB Output is correct
26 Correct 17 ms 3528 KB Output is correct
27 Correct 13 ms 3528 KB Output is correct
28 Correct 18 ms 3528 KB Output is correct
29 Correct 14 ms 3656 KB Output is correct
30 Correct 14 ms 3528 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3524 KB Output is correct
33 Correct 14 ms 3528 KB Output is correct
34 Correct 14 ms 3732 KB Output is correct
35 Correct 16 ms 3744 KB Output is correct
36 Correct 736 ms 3580 KB Output is correct
37 Correct 1133 ms 4088 KB Output is correct
38 Correct 1403 ms 4144 KB Output is correct
39 Correct 300 ms 4056 KB Output is correct
40 Correct 1490 ms 4424 KB Output is correct
41 Correct 1367 ms 4452 KB Output is correct
42 Correct 1787 ms 4264 KB Output is correct
43 Correct 1472 ms 4264 KB Output is correct
44 Correct 1804 ms 4432 KB Output is correct
45 Correct 768 ms 4424 KB Output is correct
46 Correct 1057 ms 4192 KB Output is correct
47 Correct 1700 ms 3352 KB Output is correct
48 Correct 534 ms 4160 KB Output is correct
49 Correct 1798 ms 4040 KB Output is correct
50 Correct 804 ms 3948 KB Output is correct
51 Correct 3671 ms 4032 KB Output is correct
52 Correct 3804 ms 3860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 3668 KB Output is correct
3 Correct 18 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3528 KB Output is correct
6 Correct 17 ms 3528 KB Output is correct
7 Correct 13 ms 3528 KB Output is correct
8 Correct 18 ms 3528 KB Output is correct
9 Correct 14 ms 3656 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3524 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 14 ms 3732 KB Output is correct
15 Correct 16 ms 3744 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4016 ms 4012 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 16 ms 3668 KB Output is correct
3 Correct 18 ms 3528 KB Output is correct
4 Correct 14 ms 3528 KB Output is correct
5 Correct 13 ms 3528 KB Output is correct
6 Correct 17 ms 3528 KB Output is correct
7 Correct 13 ms 3528 KB Output is correct
8 Correct 18 ms 3528 KB Output is correct
9 Correct 14 ms 3656 KB Output is correct
10 Correct 14 ms 3528 KB Output is correct
11 Correct 12 ms 3528 KB Output is correct
12 Correct 14 ms 3524 KB Output is correct
13 Correct 14 ms 3528 KB Output is correct
14 Correct 14 ms 3732 KB Output is correct
15 Correct 16 ms 3744 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4075 ms 3528 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 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 340 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 364 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 340 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 5 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 9 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 16 ms 3668 KB Output is correct
23 Correct 18 ms 3528 KB Output is correct
24 Correct 14 ms 3528 KB Output is correct
25 Correct 13 ms 3528 KB Output is correct
26 Correct 17 ms 3528 KB Output is correct
27 Correct 13 ms 3528 KB Output is correct
28 Correct 18 ms 3528 KB Output is correct
29 Correct 14 ms 3656 KB Output is correct
30 Correct 14 ms 3528 KB Output is correct
31 Correct 12 ms 3528 KB Output is correct
32 Correct 14 ms 3524 KB Output is correct
33 Correct 14 ms 3528 KB Output is correct
34 Correct 14 ms 3732 KB Output is correct
35 Correct 16 ms 3744 KB Output is correct
36 Correct 736 ms 3580 KB Output is correct
37 Correct 1133 ms 4088 KB Output is correct
38 Correct 1403 ms 4144 KB Output is correct
39 Correct 300 ms 4056 KB Output is correct
40 Correct 1490 ms 4424 KB Output is correct
41 Correct 1367 ms 4452 KB Output is correct
42 Correct 1787 ms 4264 KB Output is correct
43 Correct 1472 ms 4264 KB Output is correct
44 Correct 1804 ms 4432 KB Output is correct
45 Correct 768 ms 4424 KB Output is correct
46 Correct 1057 ms 4192 KB Output is correct
47 Correct 1700 ms 3352 KB Output is correct
48 Correct 534 ms 4160 KB Output is correct
49 Correct 1798 ms 4040 KB Output is correct
50 Correct 804 ms 3948 KB Output is correct
51 Correct 3671 ms 4032 KB Output is correct
52 Correct 3804 ms 3860 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Execution timed out 4016 ms 4012 KB Time limit exceeded
55 Halted 0 ms 0 KB -