답안 #546157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546157 2022-04-06T14:51:12 Z leaked Fish 2 (JOI22_fish2) C++14
100 / 100
1510 ms 60768 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define sz(x) (int)(x).size()
#define m_p make_pair
#define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const int N=1e5+1;
const ll inf=1e18;
struct node{
    vec<array<ll,3>> pref,suf;
    ///their value, whom not exceed,cnt
    ll s;
    node(){
        s=0;
    }
};
int a[N];
node t[4*N];
node mg(node a,node b){
    node c;
    c.s=a.s+b.s;

    c.suf=b.suf;
    c.suf.pop_back();
    c.pref=a.pref;
    c.pref.pop_back();

    /// deleted fulls

    int j=0,k=0;
    int ok=0;
    vec<int> cnt1(sz(b.pref),0);
    vec<int> cnt2(sz(a.suf),0);
    for(int i=0;i<sz(b.pref);i++){
        umax(k,i);
        ok=1;
        while(ok){
            ok=0;
            if(k<sz(b.pref) && (a.suf[j][0]+b.pref[k][0])>=b.pref[k][1]) ++k,ok=1;
            if(j<sz(a.suf) && (a.suf[j][0]+b.pref[k][0])>=a.suf[j][1]) ++j,ok=1;
        }
//        cout<<"WOW "<<j<<' '<<k<<' '<<sz(b.pref)<<' '<<sz(a.suf)<<endl;
        if(k==sz(b.pref)-1) cnt2[j]+=b.pref[i][2];
        if(j==sz(a.suf)-1) cnt1[k]+=b.pref[i][2];
    }
    j=0;k=0;
    for(int i=0;i<sz(a.suf);i++){
        umax(j,i);
        ok=1;
        while(ok){
            ok=0;
            if(k<sz(b.pref) && (a.suf[j][0]+b.pref[k][0])>=b.pref[k][1]) ++k,ok=1;
            if(j<sz(a.suf) && (a.suf[j][0]+b.pref[k][0])>=a.suf[j][1]) ++j,ok=1;
        }
//        cout<<"WOW "<<j<<' '<<k<<' '<<sz(b.pref)<<' '<<sz(a.suf)<<endl;

        if(k==sz(b.pref)-1) cnt2[j]+=a.suf[i][2];
        if(j==sz(a.suf)-1) cnt1[k]+=a.suf[i][2];
    }

    for(int i=0;i<sz(a.suf);i++){
        if(cnt2[i]){
            assert(a.suf[i][1]>=(a.suf[i][0]+b.s));
        }
        if(a.suf[i][1]>(a.suf[i][0]+b.s))
            c.suf.pb({a.suf[i][0]+b.s,a.suf[i][1],cnt2[i]});
    }

    for(int i=0;i<sz(b.pref);i++){
        if(cnt1[i]){
            assert(b.pref[i][1]>=(b.pref[i][0]+a.s));
        }
        if(b.pref[i][1]>(b.pref[i][0]+a.s))
            c.pref.pb({b.pref[i][0]+a.s,b.pref[i][1],cnt1[i]});
    }
    return c;
}
void build(int v,int tl,int tr){
    if(tl==tr){
        int x=a[tl];
        t[v].pref.clear();t[v].suf.clear();
        t[v].s=x;
        t[v].pref.pb({0,x,0});
        t[v].suf.pb({0,x,0});
        t[v].pref.pb({x,inf,1});
        t[v].suf.pb({x,inf,1});
    }
    else{
        int tm=(tl+tr)>>1;
        build(2*v,tl,tm);build(2*v+1,tm+1,tr);
//        cout<<"ME "<<tl<<' '<<tr<<endl;
        t[v]=mg(t[2*v],t[2*v+1]);
    }
}
void upd(int i,int x,int v,int tl,int tr){
    if(tl==tr){
        t[v].pref.clear();t[v].suf.clear();
        t[v].s=x;
        t[v].pref.pb({0,x,0});
        t[v].suf.pb({0,x,0});
        t[v].pref.pb({x,inf,1});
        t[v].suf.pb({x,inf,1});
        return;
    }
    int tm=(tl+tr)>>1;
    if(tm>=i)
        upd(i,x,2*v,tl,tm);
    else
        upd(i,x,2*v+1,tm+1,tr);
    t[v]=mg(t[2*v],t[2*v+1]);
}
node emp;
node get(int l,int r,int v,int tl,int tr){
    if(tl>=l&&tr<=r)
        return t[v];
    if(tl>r||tr<l)
        return emp;
    int tm=(tl+tr)>>1;
    return mg(get(l,r,2*v,tl,tm),get(l,r,2*v+1,tm+1,tr));
}
signed main(){
    fast_prep;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    build(1,0,n-1);
    emp.pref.pb({0,inf,0});
    emp.suf.pb({0,inf,0});
//    return 0;
    int q;
    cin>>q;
    while(q--){
        int tp;
        cin>>tp;
        if(tp==1){
            int i,x;
            cin>>i>>x;
            --i;
            upd(i,x,1,0,n-1);
        }
        else{
            int l,r;
            cin>>l>>r;--l;--r;
            node ans=get(l,r,1,0,n-1);
            assert(ans.suf.back()[1]==inf);
            cout<<ans.suf.back()[2]<<'\n';
        }
    }
    return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 14 ms 22232 KB Output is correct
3 Correct 11 ms 22232 KB Output is correct
4 Correct 13 ms 22228 KB Output is correct
5 Correct 15 ms 22484 KB Output is correct
6 Correct 14 ms 22356 KB Output is correct
7 Correct 15 ms 22444 KB Output is correct
8 Correct 14 ms 22356 KB Output is correct
9 Correct 14 ms 22392 KB Output is correct
10 Correct 16 ms 22388 KB Output is correct
11 Correct 14 ms 22280 KB Output is correct
12 Correct 16 ms 22356 KB Output is correct
13 Correct 14 ms 22404 KB Output is correct
14 Correct 15 ms 22356 KB Output is correct
15 Correct 14 ms 22356 KB Output is correct
16 Correct 15 ms 22436 KB Output is correct
17 Correct 15 ms 22356 KB Output is correct
18 Correct 14 ms 22356 KB Output is correct
19 Correct 15 ms 22412 KB Output is correct
20 Correct 15 ms 22296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 22248 KB Output is correct
2 Correct 116 ms 59936 KB Output is correct
3 Correct 136 ms 58572 KB Output is correct
4 Correct 123 ms 59940 KB Output is correct
5 Correct 114 ms 58752 KB Output is correct
6 Correct 104 ms 51716 KB Output is correct
7 Correct 98 ms 52064 KB Output is correct
8 Correct 103 ms 51744 KB Output is correct
9 Correct 114 ms 52148 KB Output is correct
10 Correct 116 ms 59952 KB Output is correct
11 Correct 110 ms 56116 KB Output is correct
12 Correct 102 ms 51404 KB Output is correct
13 Correct 97 ms 51316 KB Output is correct
14 Correct 110 ms 53324 KB Output is correct
15 Correct 158 ms 53544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 14 ms 22232 KB Output is correct
3 Correct 11 ms 22232 KB Output is correct
4 Correct 13 ms 22228 KB Output is correct
5 Correct 15 ms 22484 KB Output is correct
6 Correct 14 ms 22356 KB Output is correct
7 Correct 15 ms 22444 KB Output is correct
8 Correct 14 ms 22356 KB Output is correct
9 Correct 14 ms 22392 KB Output is correct
10 Correct 16 ms 22388 KB Output is correct
11 Correct 14 ms 22280 KB Output is correct
12 Correct 16 ms 22356 KB Output is correct
13 Correct 14 ms 22404 KB Output is correct
14 Correct 15 ms 22356 KB Output is correct
15 Correct 14 ms 22356 KB Output is correct
16 Correct 15 ms 22436 KB Output is correct
17 Correct 15 ms 22356 KB Output is correct
18 Correct 14 ms 22356 KB Output is correct
19 Correct 15 ms 22412 KB Output is correct
20 Correct 15 ms 22296 KB Output is correct
21 Correct 11 ms 22248 KB Output is correct
22 Correct 116 ms 59936 KB Output is correct
23 Correct 136 ms 58572 KB Output is correct
24 Correct 123 ms 59940 KB Output is correct
25 Correct 114 ms 58752 KB Output is correct
26 Correct 104 ms 51716 KB Output is correct
27 Correct 98 ms 52064 KB Output is correct
28 Correct 103 ms 51744 KB Output is correct
29 Correct 114 ms 52148 KB Output is correct
30 Correct 116 ms 59952 KB Output is correct
31 Correct 110 ms 56116 KB Output is correct
32 Correct 102 ms 51404 KB Output is correct
33 Correct 97 ms 51316 KB Output is correct
34 Correct 110 ms 53324 KB Output is correct
35 Correct 158 ms 53544 KB Output is correct
36 Correct 148 ms 59996 KB Output is correct
37 Correct 151 ms 58840 KB Output is correct
38 Correct 126 ms 58612 KB Output is correct
39 Correct 119 ms 60072 KB Output is correct
40 Correct 122 ms 58568 KB Output is correct
41 Correct 111 ms 51828 KB Output is correct
42 Correct 110 ms 51708 KB Output is correct
43 Correct 107 ms 52176 KB Output is correct
44 Correct 116 ms 52072 KB Output is correct
45 Correct 155 ms 59848 KB Output is correct
46 Correct 133 ms 59980 KB Output is correct
47 Correct 122 ms 55244 KB Output is correct
48 Correct 107 ms 51892 KB Output is correct
49 Correct 107 ms 51424 KB Output is correct
50 Correct 140 ms 53336 KB Output is correct
51 Correct 143 ms 53692 KB Output is correct
52 Correct 166 ms 53376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 22248 KB Output is correct
2 Correct 116 ms 59936 KB Output is correct
3 Correct 136 ms 58572 KB Output is correct
4 Correct 123 ms 59940 KB Output is correct
5 Correct 114 ms 58752 KB Output is correct
6 Correct 104 ms 51716 KB Output is correct
7 Correct 98 ms 52064 KB Output is correct
8 Correct 103 ms 51744 KB Output is correct
9 Correct 114 ms 52148 KB Output is correct
10 Correct 116 ms 59952 KB Output is correct
11 Correct 110 ms 56116 KB Output is correct
12 Correct 102 ms 51404 KB Output is correct
13 Correct 97 ms 51316 KB Output is correct
14 Correct 110 ms 53324 KB Output is correct
15 Correct 158 ms 53544 KB Output is correct
16 Correct 14 ms 22248 KB Output is correct
17 Correct 1458 ms 59272 KB Output is correct
18 Correct 1460 ms 60768 KB Output is correct
19 Correct 1460 ms 59288 KB Output is correct
20 Correct 1502 ms 58820 KB Output is correct
21 Correct 1469 ms 59248 KB Output is correct
22 Correct 1435 ms 60748 KB Output is correct
23 Correct 1509 ms 58980 KB Output is correct
24 Correct 1510 ms 59032 KB Output is correct
25 Correct 1419 ms 59228 KB Output is correct
26 Correct 1487 ms 59328 KB Output is correct
27 Correct 1043 ms 52252 KB Output is correct
28 Correct 1065 ms 52212 KB Output is correct
29 Correct 1079 ms 52264 KB Output is correct
30 Correct 1141 ms 52528 KB Output is correct
31 Correct 1194 ms 52360 KB Output is correct
32 Correct 1459 ms 56412 KB Output is correct
33 Correct 1431 ms 60600 KB Output is correct
34 Correct 1424 ms 56020 KB Output is correct
35 Correct 1329 ms 55176 KB Output is correct
36 Correct 1481 ms 60324 KB Output is correct
37 Correct 997 ms 51788 KB Output is correct
38 Correct 970 ms 51748 KB Output is correct
39 Correct 1063 ms 53892 KB Output is correct
40 Correct 1020 ms 54176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 22248 KB Output is correct
2 Correct 116 ms 59936 KB Output is correct
3 Correct 136 ms 58572 KB Output is correct
4 Correct 123 ms 59940 KB Output is correct
5 Correct 114 ms 58752 KB Output is correct
6 Correct 104 ms 51716 KB Output is correct
7 Correct 98 ms 52064 KB Output is correct
8 Correct 103 ms 51744 KB Output is correct
9 Correct 114 ms 52148 KB Output is correct
10 Correct 116 ms 59952 KB Output is correct
11 Correct 110 ms 56116 KB Output is correct
12 Correct 102 ms 51404 KB Output is correct
13 Correct 97 ms 51316 KB Output is correct
14 Correct 110 ms 53324 KB Output is correct
15 Correct 158 ms 53544 KB Output is correct
16 Correct 11 ms 22228 KB Output is correct
17 Correct 1018 ms 60184 KB Output is correct
18 Correct 977 ms 59092 KB Output is correct
19 Correct 718 ms 58960 KB Output is correct
20 Correct 785 ms 59264 KB Output is correct
21 Correct 956 ms 60004 KB Output is correct
22 Correct 974 ms 59164 KB Output is correct
23 Correct 905 ms 58832 KB Output is correct
24 Correct 884 ms 59276 KB Output is correct
25 Correct 823 ms 58808 KB Output is correct
26 Correct 604 ms 51976 KB Output is correct
27 Correct 877 ms 51920 KB Output is correct
28 Correct 708 ms 55164 KB Output is correct
29 Correct 688 ms 52024 KB Output is correct
30 Correct 824 ms 52164 KB Output is correct
31 Correct 861 ms 54968 KB Output is correct
32 Correct 974 ms 56688 KB Output is correct
33 Correct 808 ms 56212 KB Output is correct
34 Correct 869 ms 60128 KB Output is correct
35 Correct 709 ms 60292 KB Output is correct
36 Correct 806 ms 56048 KB Output is correct
37 Correct 812 ms 55728 KB Output is correct
38 Correct 479 ms 55564 KB Output is correct
39 Correct 638 ms 53920 KB Output is correct
40 Correct 295 ms 54220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 14 ms 22232 KB Output is correct
3 Correct 11 ms 22232 KB Output is correct
4 Correct 13 ms 22228 KB Output is correct
5 Correct 15 ms 22484 KB Output is correct
6 Correct 14 ms 22356 KB Output is correct
7 Correct 15 ms 22444 KB Output is correct
8 Correct 14 ms 22356 KB Output is correct
9 Correct 14 ms 22392 KB Output is correct
10 Correct 16 ms 22388 KB Output is correct
11 Correct 14 ms 22280 KB Output is correct
12 Correct 16 ms 22356 KB Output is correct
13 Correct 14 ms 22404 KB Output is correct
14 Correct 15 ms 22356 KB Output is correct
15 Correct 14 ms 22356 KB Output is correct
16 Correct 15 ms 22436 KB Output is correct
17 Correct 15 ms 22356 KB Output is correct
18 Correct 14 ms 22356 KB Output is correct
19 Correct 15 ms 22412 KB Output is correct
20 Correct 15 ms 22296 KB Output is correct
21 Correct 11 ms 22248 KB Output is correct
22 Correct 116 ms 59936 KB Output is correct
23 Correct 136 ms 58572 KB Output is correct
24 Correct 123 ms 59940 KB Output is correct
25 Correct 114 ms 58752 KB Output is correct
26 Correct 104 ms 51716 KB Output is correct
27 Correct 98 ms 52064 KB Output is correct
28 Correct 103 ms 51744 KB Output is correct
29 Correct 114 ms 52148 KB Output is correct
30 Correct 116 ms 59952 KB Output is correct
31 Correct 110 ms 56116 KB Output is correct
32 Correct 102 ms 51404 KB Output is correct
33 Correct 97 ms 51316 KB Output is correct
34 Correct 110 ms 53324 KB Output is correct
35 Correct 158 ms 53544 KB Output is correct
36 Correct 148 ms 59996 KB Output is correct
37 Correct 151 ms 58840 KB Output is correct
38 Correct 126 ms 58612 KB Output is correct
39 Correct 119 ms 60072 KB Output is correct
40 Correct 122 ms 58568 KB Output is correct
41 Correct 111 ms 51828 KB Output is correct
42 Correct 110 ms 51708 KB Output is correct
43 Correct 107 ms 52176 KB Output is correct
44 Correct 116 ms 52072 KB Output is correct
45 Correct 155 ms 59848 KB Output is correct
46 Correct 133 ms 59980 KB Output is correct
47 Correct 122 ms 55244 KB Output is correct
48 Correct 107 ms 51892 KB Output is correct
49 Correct 107 ms 51424 KB Output is correct
50 Correct 140 ms 53336 KB Output is correct
51 Correct 143 ms 53692 KB Output is correct
52 Correct 166 ms 53376 KB Output is correct
53 Correct 14 ms 22248 KB Output is correct
54 Correct 1458 ms 59272 KB Output is correct
55 Correct 1460 ms 60768 KB Output is correct
56 Correct 1460 ms 59288 KB Output is correct
57 Correct 1502 ms 58820 KB Output is correct
58 Correct 1469 ms 59248 KB Output is correct
59 Correct 1435 ms 60748 KB Output is correct
60 Correct 1509 ms 58980 KB Output is correct
61 Correct 1510 ms 59032 KB Output is correct
62 Correct 1419 ms 59228 KB Output is correct
63 Correct 1487 ms 59328 KB Output is correct
64 Correct 1043 ms 52252 KB Output is correct
65 Correct 1065 ms 52212 KB Output is correct
66 Correct 1079 ms 52264 KB Output is correct
67 Correct 1141 ms 52528 KB Output is correct
68 Correct 1194 ms 52360 KB Output is correct
69 Correct 1459 ms 56412 KB Output is correct
70 Correct 1431 ms 60600 KB Output is correct
71 Correct 1424 ms 56020 KB Output is correct
72 Correct 1329 ms 55176 KB Output is correct
73 Correct 1481 ms 60324 KB Output is correct
74 Correct 997 ms 51788 KB Output is correct
75 Correct 970 ms 51748 KB Output is correct
76 Correct 1063 ms 53892 KB Output is correct
77 Correct 1020 ms 54176 KB Output is correct
78 Correct 11 ms 22228 KB Output is correct
79 Correct 1018 ms 60184 KB Output is correct
80 Correct 977 ms 59092 KB Output is correct
81 Correct 718 ms 58960 KB Output is correct
82 Correct 785 ms 59264 KB Output is correct
83 Correct 956 ms 60004 KB Output is correct
84 Correct 974 ms 59164 KB Output is correct
85 Correct 905 ms 58832 KB Output is correct
86 Correct 884 ms 59276 KB Output is correct
87 Correct 823 ms 58808 KB Output is correct
88 Correct 604 ms 51976 KB Output is correct
89 Correct 877 ms 51920 KB Output is correct
90 Correct 708 ms 55164 KB Output is correct
91 Correct 688 ms 52024 KB Output is correct
92 Correct 824 ms 52164 KB Output is correct
93 Correct 861 ms 54968 KB Output is correct
94 Correct 974 ms 56688 KB Output is correct
95 Correct 808 ms 56212 KB Output is correct
96 Correct 869 ms 60128 KB Output is correct
97 Correct 709 ms 60292 KB Output is correct
98 Correct 806 ms 56048 KB Output is correct
99 Correct 812 ms 55728 KB Output is correct
100 Correct 479 ms 55564 KB Output is correct
101 Correct 638 ms 53920 KB Output is correct
102 Correct 295 ms 54220 KB Output is correct
103 Correct 1254 ms 58960 KB Output is correct
104 Correct 1058 ms 60304 KB Output is correct
105 Correct 1427 ms 59220 KB Output is correct
106 Correct 1342 ms 59412 KB Output is correct
107 Correct 1139 ms 59044 KB Output is correct
108 Correct 1067 ms 60236 KB Output is correct
109 Correct 1346 ms 58792 KB Output is correct
110 Correct 1250 ms 59244 KB Output is correct
111 Correct 1422 ms 59404 KB Output is correct
112 Correct 1339 ms 59164 KB Output is correct
113 Correct 960 ms 52232 KB Output is correct
114 Correct 1040 ms 52324 KB Output is correct
115 Correct 1060 ms 55052 KB Output is correct
116 Correct 1158 ms 55268 KB Output is correct
117 Correct 1079 ms 52408 KB Output is correct
118 Correct 1181 ms 54524 KB Output is correct
119 Correct 951 ms 51844 KB Output is correct
120 Correct 1075 ms 55204 KB Output is correct
121 Correct 1245 ms 55296 KB Output is correct
122 Correct 1122 ms 56632 KB Output is correct
123 Correct 1207 ms 56512 KB Output is correct
124 Correct 1351 ms 55856 KB Output is correct
125 Correct 1300 ms 54628 KB Output is correct
126 Correct 1331 ms 55772 KB Output is correct
127 Correct 1095 ms 55860 KB Output is correct
128 Correct 1152 ms 54068 KB Output is correct
129 Correct 1061 ms 54088 KB Output is correct
130 Correct 1093 ms 54228 KB Output is correct