답안 #818787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818787 2023-08-10T06:45:05 Z 이동현(#10134) Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 3856 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 1 ms 2644 KB Output is correct
4 Correct 1 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 3 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2572 KB Output is correct
19 Correct 7 ms 2644 KB Output is correct
20 Correct 7 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 11 ms 3796 KB Output is correct
3 Correct 9 ms 3412 KB Output is correct
4 Correct 10 ms 3668 KB Output is correct
5 Correct 9 ms 3412 KB Output is correct
6 Correct 14 ms 3716 KB Output is correct
7 Correct 10 ms 3520 KB Output is correct
8 Correct 14 ms 3668 KB Output is correct
9 Correct 13 ms 3412 KB Output is correct
10 Correct 11 ms 3412 KB Output is correct
11 Correct 9 ms 3412 KB Output is correct
12 Correct 10 ms 3668 KB Output is correct
13 Correct 14 ms 3680 KB Output is correct
14 Correct 15 ms 3724 KB Output is correct
15 Correct 12 ms 3796 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 1 ms 2644 KB Output is correct
4 Correct 1 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 3 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2572 KB Output is correct
19 Correct 7 ms 2644 KB Output is correct
20 Correct 7 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 11 ms 3796 KB Output is correct
23 Correct 9 ms 3412 KB Output is correct
24 Correct 10 ms 3668 KB Output is correct
25 Correct 9 ms 3412 KB Output is correct
26 Correct 14 ms 3716 KB Output is correct
27 Correct 10 ms 3520 KB Output is correct
28 Correct 14 ms 3668 KB Output is correct
29 Correct 13 ms 3412 KB Output is correct
30 Correct 11 ms 3412 KB Output is correct
31 Correct 9 ms 3412 KB Output is correct
32 Correct 10 ms 3668 KB Output is correct
33 Correct 14 ms 3680 KB Output is correct
34 Correct 15 ms 3724 KB Output is correct
35 Correct 12 ms 3796 KB Output is correct
36 Correct 397 ms 3552 KB Output is correct
37 Correct 698 ms 3480 KB Output is correct
38 Correct 834 ms 3496 KB Output is correct
39 Correct 162 ms 3536 KB Output is correct
40 Correct 939 ms 3480 KB Output is correct
41 Correct 912 ms 3724 KB Output is correct
42 Correct 1175 ms 3856 KB Output is correct
43 Correct 983 ms 3492 KB Output is correct
44 Correct 1162 ms 3660 KB Output is correct
45 Correct 471 ms 3420 KB Output is correct
46 Correct 638 ms 3472 KB Output is correct
47 Correct 1016 ms 3456 KB Output is correct
48 Correct 374 ms 3540 KB Output is correct
49 Correct 1391 ms 3600 KB Output is correct
50 Correct 614 ms 3788 KB Output is correct
51 Correct 2716 ms 3788 KB Output is correct
52 Correct 2993 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 11 ms 3796 KB Output is correct
3 Correct 9 ms 3412 KB Output is correct
4 Correct 10 ms 3668 KB Output is correct
5 Correct 9 ms 3412 KB Output is correct
6 Correct 14 ms 3716 KB Output is correct
7 Correct 10 ms 3520 KB Output is correct
8 Correct 14 ms 3668 KB Output is correct
9 Correct 13 ms 3412 KB Output is correct
10 Correct 11 ms 3412 KB Output is correct
11 Correct 9 ms 3412 KB Output is correct
12 Correct 10 ms 3668 KB Output is correct
13 Correct 14 ms 3680 KB Output is correct
14 Correct 15 ms 3724 KB Output is correct
15 Correct 12 ms 3796 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Execution timed out 4034 ms 3500 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 11 ms 3796 KB Output is correct
3 Correct 9 ms 3412 KB Output is correct
4 Correct 10 ms 3668 KB Output is correct
5 Correct 9 ms 3412 KB Output is correct
6 Correct 14 ms 3716 KB Output is correct
7 Correct 10 ms 3520 KB Output is correct
8 Correct 14 ms 3668 KB Output is correct
9 Correct 13 ms 3412 KB Output is correct
10 Correct 11 ms 3412 KB Output is correct
11 Correct 9 ms 3412 KB Output is correct
12 Correct 10 ms 3668 KB Output is correct
13 Correct 14 ms 3680 KB Output is correct
14 Correct 15 ms 3724 KB Output is correct
15 Correct 12 ms 3796 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Execution timed out 4046 ms 3852 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 1 ms 2644 KB Output is correct
4 Correct 1 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 3 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2572 KB Output is correct
19 Correct 7 ms 2644 KB Output is correct
20 Correct 7 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 11 ms 3796 KB Output is correct
23 Correct 9 ms 3412 KB Output is correct
24 Correct 10 ms 3668 KB Output is correct
25 Correct 9 ms 3412 KB Output is correct
26 Correct 14 ms 3716 KB Output is correct
27 Correct 10 ms 3520 KB Output is correct
28 Correct 14 ms 3668 KB Output is correct
29 Correct 13 ms 3412 KB Output is correct
30 Correct 11 ms 3412 KB Output is correct
31 Correct 9 ms 3412 KB Output is correct
32 Correct 10 ms 3668 KB Output is correct
33 Correct 14 ms 3680 KB Output is correct
34 Correct 15 ms 3724 KB Output is correct
35 Correct 12 ms 3796 KB Output is correct
36 Correct 397 ms 3552 KB Output is correct
37 Correct 698 ms 3480 KB Output is correct
38 Correct 834 ms 3496 KB Output is correct
39 Correct 162 ms 3536 KB Output is correct
40 Correct 939 ms 3480 KB Output is correct
41 Correct 912 ms 3724 KB Output is correct
42 Correct 1175 ms 3856 KB Output is correct
43 Correct 983 ms 3492 KB Output is correct
44 Correct 1162 ms 3660 KB Output is correct
45 Correct 471 ms 3420 KB Output is correct
46 Correct 638 ms 3472 KB Output is correct
47 Correct 1016 ms 3456 KB Output is correct
48 Correct 374 ms 3540 KB Output is correct
49 Correct 1391 ms 3600 KB Output is correct
50 Correct 614 ms 3788 KB Output is correct
51 Correct 2716 ms 3788 KB Output is correct
52 Correct 2993 ms 3788 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Execution timed out 4034 ms 3500 KB Time limit exceeded
55 Halted 0 ms 0 KB -