답안 #903847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903847 2024-01-11T12:21:27 Z LucaIlie Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 3364 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
int v[MAX_N + 1], leftt[MAX_N + 1], rightt[MAX_N + 1];
long long s[MAX_N + 1];

void init( int n ) {
    for ( int i = 1; i <= n; i++ )
        s[i] = s[i - 1] + v[i];

    for ( int i = 1; i < n; i++ ) {
        int l = 0, r = i + 1;
        while ( r - l > 1 ) {
            int mid = (l + r) / 2;
            if ( s[i] - s[mid - 1] >= v[i + 1] )
                l = mid;
            else
                r = mid;
        }
        leftt[i] = l;
    }

    for ( int i = 2; i <= n; i++ ) {
        int l = i - 1, r = n + 1;
        while ( r - l > 1 ) {
            int mid = (l + r) / 2;
            if ( s[mid] - s[i - 1] >= v[i - 1] )
                r = mid;
            else
                l = mid;
        }
        rightt[i] = r;
    }
}

int main() {
    cin.tie( NULL );
    cout.tie( NULL );
    ios_base::sync_with_stdio( false );
    
    int n;

    cin >> n;
    for ( int i = 1; i <= n; i++ )
        cin >> v[i];

    init( n );

    int q;
    cin >> q;
    while ( q-- ) {
        int t, l, r;

        cin >> t >> l >> r;

        if ( t == 1 ) {
            v[l] = r;
            init( n );
            continue;
        }

        int ans = 0;
        for ( int i = l; i <= r; i++ ) {
            int p;

            p = i;
            while ( p >= l + 1 && (rightt[p] <= i || (rightt[p] <= r && leftt[rightt[p] - 1] >= p)) )
                p--;

            if ( p != l )
                continue;

            p = i;
            while ( p <= r - 1 && (leftt[p] >= i || (leftt[p] >= l && rightt[leftt[p] + 1] <= p)) )
                p++;
            if ( p == r )
                ans++;
        }

        cout << ans << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 15 ms 488 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 12 ms 488 KB Output is correct
10 Correct 12 ms 344 KB Output is correct
11 Correct 11 ms 344 KB Output is correct
12 Correct 12 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 12 ms 488 KB Output is correct
15 Correct 9 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 12 ms 488 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 11 ms 500 KB Output is correct
20 Correct 29 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 670 ms 2388 KB Output is correct
3 Correct 106 ms 2396 KB Output is correct
4 Correct 1786 ms 2396 KB Output is correct
5 Correct 179 ms 2396 KB Output is correct
6 Correct 3949 ms 2392 KB Output is correct
7 Correct 258 ms 2648 KB Output is correct
8 Correct 3906 ms 3364 KB Output is correct
9 Correct 216 ms 2396 KB Output is correct
10 Correct 456 ms 2980 KB Output is correct
11 Correct 39 ms 2672 KB Output is correct
12 Correct 1296 ms 2652 KB Output is correct
13 Correct 1386 ms 2648 KB Output is correct
14 Correct 2536 ms 2988 KB Output is correct
15 Correct 2370 ms 2996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 15 ms 488 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 12 ms 488 KB Output is correct
10 Correct 12 ms 344 KB Output is correct
11 Correct 11 ms 344 KB Output is correct
12 Correct 12 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 12 ms 488 KB Output is correct
15 Correct 9 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 12 ms 488 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 11 ms 500 KB Output is correct
20 Correct 29 ms 464 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 670 ms 2388 KB Output is correct
23 Correct 106 ms 2396 KB Output is correct
24 Correct 1786 ms 2396 KB Output is correct
25 Correct 179 ms 2396 KB Output is correct
26 Correct 3949 ms 2392 KB Output is correct
27 Correct 258 ms 2648 KB Output is correct
28 Correct 3906 ms 3364 KB Output is correct
29 Correct 216 ms 2396 KB Output is correct
30 Correct 456 ms 2980 KB Output is correct
31 Correct 39 ms 2672 KB Output is correct
32 Correct 1296 ms 2652 KB Output is correct
33 Correct 1386 ms 2648 KB Output is correct
34 Correct 2536 ms 2988 KB Output is correct
35 Correct 2370 ms 2996 KB Output is correct
36 Execution timed out 4027 ms 2908 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 670 ms 2388 KB Output is correct
3 Correct 106 ms 2396 KB Output is correct
4 Correct 1786 ms 2396 KB Output is correct
5 Correct 179 ms 2396 KB Output is correct
6 Correct 3949 ms 2392 KB Output is correct
7 Correct 258 ms 2648 KB Output is correct
8 Correct 3906 ms 3364 KB Output is correct
9 Correct 216 ms 2396 KB Output is correct
10 Correct 456 ms 2980 KB Output is correct
11 Correct 39 ms 2672 KB Output is correct
12 Correct 1296 ms 2652 KB Output is correct
13 Correct 1386 ms 2648 KB Output is correct
14 Correct 2536 ms 2988 KB Output is correct
15 Correct 2370 ms 2996 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4056 ms 2652 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 670 ms 2388 KB Output is correct
3 Correct 106 ms 2396 KB Output is correct
4 Correct 1786 ms 2396 KB Output is correct
5 Correct 179 ms 2396 KB Output is correct
6 Correct 3949 ms 2392 KB Output is correct
7 Correct 258 ms 2648 KB Output is correct
8 Correct 3906 ms 3364 KB Output is correct
9 Correct 216 ms 2396 KB Output is correct
10 Correct 456 ms 2980 KB Output is correct
11 Correct 39 ms 2672 KB Output is correct
12 Correct 1296 ms 2652 KB Output is correct
13 Correct 1386 ms 2648 KB Output is correct
14 Correct 2536 ms 2988 KB Output is correct
15 Correct 2370 ms 2996 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Execution timed out 4035 ms 2980 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 15 ms 488 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 11 ms 596 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 12 ms 488 KB Output is correct
10 Correct 12 ms 344 KB Output is correct
11 Correct 11 ms 344 KB Output is correct
12 Correct 12 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 12 ms 488 KB Output is correct
15 Correct 9 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 12 ms 488 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 11 ms 500 KB Output is correct
20 Correct 29 ms 464 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 670 ms 2388 KB Output is correct
23 Correct 106 ms 2396 KB Output is correct
24 Correct 1786 ms 2396 KB Output is correct
25 Correct 179 ms 2396 KB Output is correct
26 Correct 3949 ms 2392 KB Output is correct
27 Correct 258 ms 2648 KB Output is correct
28 Correct 3906 ms 3364 KB Output is correct
29 Correct 216 ms 2396 KB Output is correct
30 Correct 456 ms 2980 KB Output is correct
31 Correct 39 ms 2672 KB Output is correct
32 Correct 1296 ms 2652 KB Output is correct
33 Correct 1386 ms 2648 KB Output is correct
34 Correct 2536 ms 2988 KB Output is correct
35 Correct 2370 ms 2996 KB Output is correct
36 Execution timed out 4027 ms 2908 KB Time limit exceeded
37 Halted 0 ms 0 KB -