답안 #755555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755555 2023-06-10T10:46:16 Z bachhoangxuan Mizuyokan 2 (JOI23_mizuyokan2) C++17
100 / 100
711 ms 14308 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=250005;
const int bl=400;
const int maxs=650;
const int maxm=200005;
const int maxq=500005;
const int maxl=65;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
void solve(){
    int n;cin >> n;
    vector<int> L(n,0),nxt(n,0),f(n,0);
    vector<pii> jmp(n);
    for(int i=0;i<n;i++) cin >> L[i];
    auto cal_f = [&](int i){
        int sum=0,j=i-1,st=max(0LL,i-maxl);
        while(j>=st && sum<=max(L[i],L[j])) sum+=L[j--];
        f[i]=(j>=st?j:-1);
    };
    auto cal_nxt = [&](int i){
        nxt[i]=i+1;
        while(nxt[i]<n && f[nxt[i]]<i) nxt[i]++;
    };
    auto build_jmp = [&](int x){
        for(int i=min(n,(x+1)*bl)-1;i>=x*bl;i--){
            int cur=nxt[i];
            if(cur<n && cur/bl==x) jmp[i]=jmp[cur],jmp[i].se++;
            else jmp[i]={cur,1};
        }
    };
    for(int i=0;i<n;i++) cal_f(i);
    for(int i=0;i<n;i++) cal_nxt(i);
    for(int i=0;i<=(n-1)/bl;i++) build_jmp(i);
    auto update = [&](int x,int y){
        L[--x]=y;
        int st=max(x-maxl,0LL),en=min(x+maxl,n-1);
        for(int i=x;i<=min(x+maxl,n-1);i++) cal_f(i);
        for(int i=st;i<=en;i++) cal_nxt(i);
        build_jmp(en/bl);
        if(en/bl!=st/bl) build_jmp(st/bl);
    };
    auto query = [&](int l,int r){
        if(l>r) return -inf;
        int cnt=0;
        while(nxt[l]<=r){
            if(jmp[l].fi<=r) cnt+=jmp[l].se,l=jmp[l].fi;
            else cnt++,l=nxt[l];
        }
        return cnt;
    };
    auto cal = [&](int l,int r){
        r--;
        int lt=l,sum=0;
        while(lt<n && sum<=L[lt]) sum+=L[lt++];
        int rt=r;sum=0;
        while(rt>=0 && sum<=L[rt]) sum+=L[rt--];
        int res=1;
        res=max(res,query(l,r)*2+1);
        res=max(res,max(query(lt,r),query(l,rt))*2+2);
        res=max(res,query(lt,rt)*2+3);
        return res;
    };
    int q;cin >> q;
    for(int i=1;i<=q;i++){
        int x,y,a,b;cin >> x >> y >> a >> b;
        update(x,y);
        cout << cal(a,b) << '\n';
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 420 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 420 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 28 ms 10668 KB Output is correct
42 Correct 29 ms 12236 KB Output is correct
43 Correct 28 ms 12156 KB Output is correct
44 Correct 24 ms 8652 KB Output is correct
45 Correct 34 ms 12404 KB Output is correct
46 Correct 37 ms 11512 KB Output is correct
47 Correct 25 ms 8980 KB Output is correct
48 Correct 37 ms 11772 KB Output is correct
49 Correct 37 ms 11600 KB Output is correct
50 Correct 37 ms 11468 KB Output is correct
51 Correct 44 ms 11516 KB Output is correct
52 Correct 25 ms 9484 KB Output is correct
53 Correct 33 ms 12416 KB Output is correct
54 Correct 28 ms 11384 KB Output is correct
55 Correct 23 ms 11396 KB Output is correct
56 Correct 31 ms 11392 KB Output is correct
57 Correct 24 ms 11404 KB Output is correct
58 Correct 32 ms 11384 KB Output is correct
59 Correct 32 ms 12396 KB Output is correct
60 Correct 31 ms 12524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 187 ms 10600 KB Output is correct
3 Correct 221 ms 13900 KB Output is correct
4 Correct 200 ms 13676 KB Output is correct
5 Correct 264 ms 13900 KB Output is correct
6 Correct 684 ms 13208 KB Output is correct
7 Correct 684 ms 13396 KB Output is correct
8 Correct 658 ms 13200 KB Output is correct
9 Correct 711 ms 13056 KB Output is correct
10 Correct 488 ms 10992 KB Output is correct
11 Correct 667 ms 14308 KB Output is correct
12 Correct 629 ms 13044 KB Output is correct
13 Correct 517 ms 12996 KB Output is correct
14 Correct 535 ms 13004 KB Output is correct
15 Correct 622 ms 13040 KB Output is correct
16 Correct 637 ms 12924 KB Output is correct
17 Correct 268 ms 14060 KB Output is correct
18 Correct 314 ms 14300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 169 ms 12056 KB Output is correct
4 Correct 204 ms 12868 KB Output is correct
5 Correct 222 ms 12780 KB Output is correct
6 Correct 502 ms 12692 KB Output is correct
7 Correct 594 ms 12792 KB Output is correct
8 Correct 638 ms 12536 KB Output is correct
9 Correct 575 ms 12704 KB Output is correct
10 Correct 613 ms 13388 KB Output is correct
11 Correct 633 ms 12448 KB Output is correct
12 Correct 608 ms 12476 KB Output is correct
13 Correct 665 ms 12528 KB Output is correct
14 Correct 621 ms 12364 KB Output is correct
15 Correct 597 ms 12684 KB Output is correct
16 Correct 259 ms 12980 KB Output is correct
17 Correct 316 ms 13108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 420 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 28 ms 10668 KB Output is correct
42 Correct 29 ms 12236 KB Output is correct
43 Correct 28 ms 12156 KB Output is correct
44 Correct 24 ms 8652 KB Output is correct
45 Correct 34 ms 12404 KB Output is correct
46 Correct 37 ms 11512 KB Output is correct
47 Correct 25 ms 8980 KB Output is correct
48 Correct 37 ms 11772 KB Output is correct
49 Correct 37 ms 11600 KB Output is correct
50 Correct 37 ms 11468 KB Output is correct
51 Correct 44 ms 11516 KB Output is correct
52 Correct 25 ms 9484 KB Output is correct
53 Correct 33 ms 12416 KB Output is correct
54 Correct 28 ms 11384 KB Output is correct
55 Correct 23 ms 11396 KB Output is correct
56 Correct 31 ms 11392 KB Output is correct
57 Correct 24 ms 11404 KB Output is correct
58 Correct 32 ms 11384 KB Output is correct
59 Correct 32 ms 12396 KB Output is correct
60 Correct 31 ms 12524 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 187 ms 10600 KB Output is correct
63 Correct 221 ms 13900 KB Output is correct
64 Correct 200 ms 13676 KB Output is correct
65 Correct 264 ms 13900 KB Output is correct
66 Correct 684 ms 13208 KB Output is correct
67 Correct 684 ms 13396 KB Output is correct
68 Correct 658 ms 13200 KB Output is correct
69 Correct 711 ms 13056 KB Output is correct
70 Correct 488 ms 10992 KB Output is correct
71 Correct 667 ms 14308 KB Output is correct
72 Correct 629 ms 13044 KB Output is correct
73 Correct 517 ms 12996 KB Output is correct
74 Correct 535 ms 13004 KB Output is correct
75 Correct 622 ms 13040 KB Output is correct
76 Correct 637 ms 12924 KB Output is correct
77 Correct 268 ms 14060 KB Output is correct
78 Correct 314 ms 14300 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 169 ms 12056 KB Output is correct
82 Correct 204 ms 12868 KB Output is correct
83 Correct 222 ms 12780 KB Output is correct
84 Correct 502 ms 12692 KB Output is correct
85 Correct 594 ms 12792 KB Output is correct
86 Correct 638 ms 12536 KB Output is correct
87 Correct 575 ms 12704 KB Output is correct
88 Correct 613 ms 13388 KB Output is correct
89 Correct 633 ms 12448 KB Output is correct
90 Correct 608 ms 12476 KB Output is correct
91 Correct 665 ms 12528 KB Output is correct
92 Correct 621 ms 12364 KB Output is correct
93 Correct 597 ms 12684 KB Output is correct
94 Correct 259 ms 12980 KB Output is correct
95 Correct 316 ms 13108 KB Output is correct
96 Correct 161 ms 10340 KB Output is correct
97 Correct 231 ms 13792 KB Output is correct
98 Correct 227 ms 13944 KB Output is correct
99 Correct 709 ms 13248 KB Output is correct
100 Correct 671 ms 13308 KB Output is correct
101 Correct 622 ms 13164 KB Output is correct
102 Correct 676 ms 13052 KB Output is correct
103 Correct 610 ms 14284 KB Output is correct
104 Correct 601 ms 13020 KB Output is correct
105 Correct 590 ms 12920 KB Output is correct
106 Correct 605 ms 13000 KB Output is correct
107 Correct 617 ms 13028 KB Output is correct
108 Correct 639 ms 13112 KB Output is correct
109 Correct 266 ms 14076 KB Output is correct
110 Correct 313 ms 14296 KB Output is correct