답안 #905151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
905151 2024-01-12T16:25:06 Z Ahmed57 Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 9220 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;
    while(q--){
    int ty,LL,RR;cin>>ty>>LL>>RR;
    if(ty==1){
        arr[LL] = RR;
        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]);
                }
            }
        }
        continue;
    }
    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 356 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 472 KB Output is correct
5 Correct 13 ms 356 KB Output is correct
6 Correct 12 ms 356 KB Output is correct
7 Correct 10 ms 356 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 15 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 7 ms 344 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 15 ms 344 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 12 ms 344 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 22 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 31 ms 9048 KB Output is correct
3 Correct 32 ms 9052 KB Output is correct
4 Correct 29 ms 9052 KB Output is correct
5 Correct 28 ms 9064 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 31 ms 9048 KB Output is correct
9 Correct 60 ms 9048 KB Output is correct
10 Correct 35 ms 9052 KB Output is correct
11 Correct 37 ms 9052 KB Output is correct
12 Correct 38 ms 9052 KB Output is correct
13 Correct 43 ms 9220 KB Output is correct
14 Correct 30 ms 9052 KB Output is correct
15 Correct 35 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 472 KB Output is correct
5 Correct 13 ms 356 KB Output is correct
6 Correct 12 ms 356 KB Output is correct
7 Correct 10 ms 356 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 15 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 7 ms 344 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 15 ms 344 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 12 ms 344 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 22 ms 348 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 31 ms 9048 KB Output is correct
23 Correct 32 ms 9052 KB Output is correct
24 Correct 29 ms 9052 KB Output is correct
25 Correct 28 ms 9064 KB Output is correct
26 Correct 33 ms 9052 KB Output is correct
27 Correct 65 ms 9048 KB Output is correct
28 Correct 31 ms 9048 KB Output is correct
29 Correct 60 ms 9048 KB Output is correct
30 Correct 35 ms 9052 KB Output is correct
31 Correct 37 ms 9052 KB Output is correct
32 Correct 38 ms 9052 KB Output is correct
33 Correct 43 ms 9220 KB Output is correct
34 Correct 30 ms 9052 KB Output is correct
35 Correct 35 ms 9048 KB Output is correct
36 Execution timed out 4054 ms 9052 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 31 ms 9048 KB Output is correct
3 Correct 32 ms 9052 KB Output is correct
4 Correct 29 ms 9052 KB Output is correct
5 Correct 28 ms 9064 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 31 ms 9048 KB Output is correct
9 Correct 60 ms 9048 KB Output is correct
10 Correct 35 ms 9052 KB Output is correct
11 Correct 37 ms 9052 KB Output is correct
12 Correct 38 ms 9052 KB Output is correct
13 Correct 43 ms 9220 KB Output is correct
14 Correct 30 ms 9052 KB Output is correct
15 Correct 35 ms 9048 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4051 ms 9052 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 31 ms 9048 KB Output is correct
3 Correct 32 ms 9052 KB Output is correct
4 Correct 29 ms 9052 KB Output is correct
5 Correct 28 ms 9064 KB Output is correct
6 Correct 33 ms 9052 KB Output is correct
7 Correct 65 ms 9048 KB Output is correct
8 Correct 31 ms 9048 KB Output is correct
9 Correct 60 ms 9048 KB Output is correct
10 Correct 35 ms 9052 KB Output is correct
11 Correct 37 ms 9052 KB Output is correct
12 Correct 38 ms 9052 KB Output is correct
13 Correct 43 ms 9220 KB Output is correct
14 Correct 30 ms 9052 KB Output is correct
15 Correct 35 ms 9048 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Execution timed out 4046 ms 9048 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 472 KB Output is correct
5 Correct 13 ms 356 KB Output is correct
6 Correct 12 ms 356 KB Output is correct
7 Correct 10 ms 356 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 15 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 7 ms 344 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 15 ms 344 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 12 ms 344 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 22 ms 348 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 31 ms 9048 KB Output is correct
23 Correct 32 ms 9052 KB Output is correct
24 Correct 29 ms 9052 KB Output is correct
25 Correct 28 ms 9064 KB Output is correct
26 Correct 33 ms 9052 KB Output is correct
27 Correct 65 ms 9048 KB Output is correct
28 Correct 31 ms 9048 KB Output is correct
29 Correct 60 ms 9048 KB Output is correct
30 Correct 35 ms 9052 KB Output is correct
31 Correct 37 ms 9052 KB Output is correct
32 Correct 38 ms 9052 KB Output is correct
33 Correct 43 ms 9220 KB Output is correct
34 Correct 30 ms 9052 KB Output is correct
35 Correct 35 ms 9048 KB Output is correct
36 Execution timed out 4054 ms 9052 KB Time limit exceeded
37 Halted 0 ms 0 KB -