답안 #596861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596861 2022-07-15T08:12:16 Z 이동현(#8450) Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 3844 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize9("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

const int NS = (int)1e5 + 4;
int acnt[NS];
vector<long long> stk[NS];
int stkN;
int ans[NS];
int ansN;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int q; cin >> q;
    while(q--){
        int t, x, y; cin >> t >> x >> y;
        if(t == 1){
            --x;
            a[x] = y;
        }
        else{
            --x, --y;
            for(int i = x; i <= y; ++i) acnt[i] = 0;
            stkN = ansN = 0;
            stk[stkN++] = {(int)1e9, x - 1, 0};
            long long sum = 0;
            for(int i = x; i <= y; ++i){
                while(stk[stkN - 1][0] < a[i]){
                    --stkN;
                }
                if(sum - stk[stkN - 1][2] < a[i]){
                    while(ansN && ans[ansN - 1] > stk[stkN - 1][1]){
                        --ansN;
                    }
                }
                sum += a[i];
                stk[stkN++] = {a[i], i, sum};
                ans[ansN++] = i;
            }
            for(int i = 0; i < ansN; ++i) ++acnt[ans[i]];
            stkN = ansN = 0;
            stk[stkN++] = {(int)1e9, y + 1, 0};
            sum = 0;
            for(int i = y; i >= x; --i){
                while(stk[stkN - 1][0] < a[i]){
                    --stkN;
                }
                if(sum - stk[stkN - 1][2] < a[i]){
                    while(ansN && ans[ansN - 1] < stk[stkN - 1][1]){
                        --ansN;
                    }
                }
                sum += a[i];
                stk[stkN++] = {a[i], i, sum};
                ans[ansN++] = i;
            }
            for(int i = 0; i < ansN; ++i) ++acnt[ans[i]];
            int dap = 0;
            for(int i = x; i <= y; ++i) dap += (acnt[i] == 2);
            cout << dap << '\n';
        }
    }
    return 0;
}

Compilation message

fish2.cpp:3: warning: ignoring '#pragma GCC optimize9' [-Wunknown-pragmas]
    3 | #pragma GCC optimize9("Ofast")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 5 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 5 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 7 ms 2684 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 7 ms 2676 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 11 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 13 ms 3844 KB Output is correct
3 Correct 14 ms 3448 KB Output is correct
4 Correct 13 ms 3668 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 17 ms 3668 KB Output is correct
7 Correct 12 ms 3468 KB Output is correct
8 Correct 16 ms 3668 KB Output is correct
9 Correct 11 ms 3412 KB Output is correct
10 Correct 16 ms 3464 KB Output is correct
11 Correct 13 ms 3412 KB Output is correct
12 Correct 13 ms 3716 KB Output is correct
13 Correct 12 ms 3592 KB Output is correct
14 Correct 14 ms 3716 KB Output is correct
15 Correct 19 ms 3720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 5 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 5 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 7 ms 2684 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 7 ms 2676 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 11 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 13 ms 3844 KB Output is correct
23 Correct 14 ms 3448 KB Output is correct
24 Correct 13 ms 3668 KB Output is correct
25 Correct 15 ms 3412 KB Output is correct
26 Correct 17 ms 3668 KB Output is correct
27 Correct 12 ms 3468 KB Output is correct
28 Correct 16 ms 3668 KB Output is correct
29 Correct 11 ms 3412 KB Output is correct
30 Correct 16 ms 3464 KB Output is correct
31 Correct 13 ms 3412 KB Output is correct
32 Correct 13 ms 3716 KB Output is correct
33 Correct 12 ms 3592 KB Output is correct
34 Correct 14 ms 3716 KB Output is correct
35 Correct 19 ms 3720 KB Output is correct
36 Correct 485 ms 3552 KB Output is correct
37 Correct 940 ms 3488 KB Output is correct
38 Correct 1138 ms 3500 KB Output is correct
39 Correct 216 ms 3624 KB Output is correct
40 Correct 1244 ms 3484 KB Output is correct
41 Correct 1216 ms 3724 KB Output is correct
42 Correct 1568 ms 3824 KB Output is correct
43 Correct 1223 ms 3524 KB Output is correct
44 Correct 1464 ms 3544 KB Output is correct
45 Correct 555 ms 3492 KB Output is correct
46 Correct 806 ms 3476 KB Output is correct
47 Correct 1308 ms 3448 KB Output is correct
48 Correct 451 ms 3540 KB Output is correct
49 Correct 1515 ms 3600 KB Output is correct
50 Correct 700 ms 3788 KB Output is correct
51 Correct 3249 ms 3780 KB Output is correct
52 Correct 3565 ms 3784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 13 ms 3844 KB Output is correct
3 Correct 14 ms 3448 KB Output is correct
4 Correct 13 ms 3668 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 17 ms 3668 KB Output is correct
7 Correct 12 ms 3468 KB Output is correct
8 Correct 16 ms 3668 KB Output is correct
9 Correct 11 ms 3412 KB Output is correct
10 Correct 16 ms 3464 KB Output is correct
11 Correct 13 ms 3412 KB Output is correct
12 Correct 13 ms 3716 KB Output is correct
13 Correct 12 ms 3592 KB Output is correct
14 Correct 14 ms 3716 KB Output is correct
15 Correct 19 ms 3720 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Execution timed out 4019 ms 3568 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 13 ms 3844 KB Output is correct
3 Correct 14 ms 3448 KB Output is correct
4 Correct 13 ms 3668 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 17 ms 3668 KB Output is correct
7 Correct 12 ms 3468 KB Output is correct
8 Correct 16 ms 3668 KB Output is correct
9 Correct 11 ms 3412 KB Output is correct
10 Correct 16 ms 3464 KB Output is correct
11 Correct 13 ms 3412 KB Output is correct
12 Correct 13 ms 3716 KB Output is correct
13 Correct 12 ms 3592 KB Output is correct
14 Correct 14 ms 3716 KB Output is correct
15 Correct 19 ms 3720 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Execution timed out 4038 ms 3836 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 5 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 5 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 7 ms 2684 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 7 ms 2676 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 11 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 13 ms 3844 KB Output is correct
23 Correct 14 ms 3448 KB Output is correct
24 Correct 13 ms 3668 KB Output is correct
25 Correct 15 ms 3412 KB Output is correct
26 Correct 17 ms 3668 KB Output is correct
27 Correct 12 ms 3468 KB Output is correct
28 Correct 16 ms 3668 KB Output is correct
29 Correct 11 ms 3412 KB Output is correct
30 Correct 16 ms 3464 KB Output is correct
31 Correct 13 ms 3412 KB Output is correct
32 Correct 13 ms 3716 KB Output is correct
33 Correct 12 ms 3592 KB Output is correct
34 Correct 14 ms 3716 KB Output is correct
35 Correct 19 ms 3720 KB Output is correct
36 Correct 485 ms 3552 KB Output is correct
37 Correct 940 ms 3488 KB Output is correct
38 Correct 1138 ms 3500 KB Output is correct
39 Correct 216 ms 3624 KB Output is correct
40 Correct 1244 ms 3484 KB Output is correct
41 Correct 1216 ms 3724 KB Output is correct
42 Correct 1568 ms 3824 KB Output is correct
43 Correct 1223 ms 3524 KB Output is correct
44 Correct 1464 ms 3544 KB Output is correct
45 Correct 555 ms 3492 KB Output is correct
46 Correct 806 ms 3476 KB Output is correct
47 Correct 1308 ms 3448 KB Output is correct
48 Correct 451 ms 3540 KB Output is correct
49 Correct 1515 ms 3600 KB Output is correct
50 Correct 700 ms 3788 KB Output is correct
51 Correct 3249 ms 3780 KB Output is correct
52 Correct 3565 ms 3784 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Execution timed out 4019 ms 3568 KB Time limit exceeded
55 Halted 0 ms 0 KB -