답안 #905163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
905163 2024-01-12T16:48:09 Z Ahmed57 Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 9404 KB
//#include "dango3.h"
 
#include <bits/stdc++.h>
using namespace std;
int logg[100001],sp[100001][17];
int get(int l,int r){
    int sz = r-l+1;
    int lo = logg[sz];
    return max(sp[l][lo],sp[r-(1<<lo)+1][lo]);
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("outout.txt","w",stdout);
    int n;
    cin>>n;
    long long arr[n+1],pref[n+1] = {0};
    for(int i = 1;i<=n;i++){
        cin>>arr[i];
        sp[i][0] = arr[i];
        pref[i] = arr[i]+pref[i-1];
    }
    logg[1] = 0;
    for(int i = 2;i<=n;i++){
        logg[i] = logg[i/2]+1;
    }
    for(int i = n;i>=1;i--){
        for(int j = 1;j<17;j++){
            if(i+(1<<j)-1<=n){
                sp[i][j] = max(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
            }
        }
    }
    int q;cin>>q;
    bool update = 0;
    while(q--){
    int ty,LL,RR;cin>>ty>>LL>>RR;
    if(ty==1){
        arr[LL] = RR;
        update = 1;
        continue;
    }
    if(update){
        update = 0;
        for(int i = 1;i<=n;i++){
            pref[i] = arr[i]+pref[i-1];
            sp[i][0] = arr[i];
        }
        for(int i = n;i>=1;i--){
            for(int j = 1;j<17;j++){
                if(i+(1<<j)-1<=n){
                    sp[i][j] = max(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
                }
            }
        }
    }
    int fin = 0;
    for(int i = LL;i<=RR;i++){
        int cnt = 0;
        long long l = i , r = i , sum = 0;
        bool ss = 0;
        while(cnt<=1){
            sum = pref[r]-pref[l-1];
            if(ss==0){
                int L = LL , R = l-1 , ans = l;
                while(L<=R){
                    int mid = (L+R)/2;
                    if(get(mid,l-1)<=sum){
                        ans = mid;
                        R = mid-1;
                    }else L = mid+1;
                }
                if(l==ans){
                    cnt++;
                }else{
                    l = ans;
                    cnt = 0;
                }
            }else{
                int L = r+1 , R = RR , ans = r;
                while(L<=R){
                    int mid = (L+R)/2;
                    if(get(r+1,mid)<=sum){
                        ans = mid;
                        L = mid+1;
                    }else R = mid-1;
                }
                if(r==ans){
                    cnt++;
                }else{
                    r = ans;
                    cnt = 0;
                }
            }
            ss = !ss;
        }
        if(l==LL&&r==RR){
            fin++;
        }
    }
    cout<<fin<<endl;
}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 10 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 7 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 11 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Correct 14 ms 348 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 11 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 19 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 35 ms 9048 KB Output is correct
3 Correct 36 ms 9048 KB Output is correct
4 Correct 29 ms 9048 KB Output is correct
5 Correct 28 ms 9052 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 40 ms 9204 KB Output is correct
9 Correct 61 ms 9052 KB Output is correct
10 Correct 38 ms 9048 KB Output is correct
11 Correct 33 ms 9052 KB Output is correct
12 Correct 38 ms 9048 KB Output is correct
13 Correct 39 ms 9052 KB Output is correct
14 Correct 30 ms 8872 KB Output is correct
15 Correct 32 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 10 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 7 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 11 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Correct 14 ms 348 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 11 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 19 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 35 ms 9048 KB Output is correct
23 Correct 36 ms 9048 KB Output is correct
24 Correct 29 ms 9048 KB Output is correct
25 Correct 28 ms 9052 KB Output is correct
26 Correct 33 ms 9052 KB Output is correct
27 Correct 65 ms 9048 KB Output is correct
28 Correct 40 ms 9204 KB Output is correct
29 Correct 61 ms 9052 KB Output is correct
30 Correct 38 ms 9048 KB Output is correct
31 Correct 33 ms 9052 KB Output is correct
32 Correct 38 ms 9048 KB Output is correct
33 Correct 39 ms 9052 KB Output is correct
34 Correct 30 ms 8872 KB Output is correct
35 Correct 32 ms 9048 KB Output is correct
36 Correct 3348 ms 9048 KB Output is correct
37 Execution timed out 4048 ms 9404 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 35 ms 9048 KB Output is correct
3 Correct 36 ms 9048 KB Output is correct
4 Correct 29 ms 9048 KB Output is correct
5 Correct 28 ms 9052 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 40 ms 9204 KB Output is correct
9 Correct 61 ms 9052 KB Output is correct
10 Correct 38 ms 9048 KB Output is correct
11 Correct 33 ms 9052 KB Output is correct
12 Correct 38 ms 9048 KB Output is correct
13 Correct 39 ms 9052 KB Output is correct
14 Correct 30 ms 8872 KB Output is correct
15 Correct 32 ms 9048 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Execution timed out 4049 ms 8868 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 35 ms 9048 KB Output is correct
3 Correct 36 ms 9048 KB Output is correct
4 Correct 29 ms 9048 KB Output is correct
5 Correct 28 ms 9052 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 40 ms 9204 KB Output is correct
9 Correct 61 ms 9052 KB Output is correct
10 Correct 38 ms 9048 KB Output is correct
11 Correct 33 ms 9052 KB Output is correct
12 Correct 38 ms 9048 KB Output is correct
13 Correct 39 ms 9052 KB Output is correct
14 Correct 30 ms 8872 KB Output is correct
15 Correct 32 ms 9048 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4030 ms 8872 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 10 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 7 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 11 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Correct 14 ms 348 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 11 ms 348 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 19 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 35 ms 9048 KB Output is correct
23 Correct 36 ms 9048 KB Output is correct
24 Correct 29 ms 9048 KB Output is correct
25 Correct 28 ms 9052 KB Output is correct
26 Correct 33 ms 9052 KB Output is correct
27 Correct 65 ms 9048 KB Output is correct
28 Correct 40 ms 9204 KB Output is correct
29 Correct 61 ms 9052 KB Output is correct
30 Correct 38 ms 9048 KB Output is correct
31 Correct 33 ms 9052 KB Output is correct
32 Correct 38 ms 9048 KB Output is correct
33 Correct 39 ms 9052 KB Output is correct
34 Correct 30 ms 8872 KB Output is correct
35 Correct 32 ms 9048 KB Output is correct
36 Correct 3348 ms 9048 KB Output is correct
37 Execution timed out 4048 ms 9404 KB Time limit exceeded
38 Halted 0 ms 0 KB -