Submission #926786

# Submission time Handle Problem Language Result Execution time Memory
926786 2024-02-13T17:46:22 Z winter0101 Fish 2 (JOI22_fish2) C++14
100 / 100
2866 ms 77924 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=1e5+9;
struct line{
int l,r,num;
long long val;
bool operator < (const line &p){
if (val==p.val&&l==p.l)return r<p.r;
if (val==p.val)return l<p.l;
return val<p.val;
}
};
struct arr{
int l,r;
long long sum;
};
struct node{
int l,r;
vector<arr>pf,sf;
vector<line>tmp;
long long sum;
node(){
sum=0;
pf.clear(),sf.clear(),tmp.clear();
}
}st[maxn*4];
long long a[maxn];
node merge(const node &p,const node &q){
if (p.pf.empty())return q;
if (q.pf.empty())return p;
node r;
r.pf=p.pf;
long long sum=0;
for (auto v:p.pf)sum+=v.sum;
for (auto v:q.pf){
if (sum>=a[v.l]){
r.pf.back().sum+=v.sum;
r.pf.back().r=v.r;
sum+=v.sum;
}
else {
r.pf.pb(v);
sum+=v.sum;
}
}
sum=0;
r.sf=q.sf;
for (auto v:q.sf)sum+=v.sum;
for (auto v:p.sf){
if (sum>=a[v.r]){
r.sf.back().sum+=v.sum;
r.sf.back().l=v.l;
sum+=v.sum;
}
else {
r.sf.pb(v);
sum+=v.sum;
}
}
r.sum=p.sum+q.sum;
r.l=p.l,r.r=q.r;
vector<line>temp;
for (auto u:p.tmp){
auto v=u;
if (v.r==p.r){
int i1=0,i2=0;
while (true){
if (i1<sz(p.sf)&&p.sf[i1].l>=v.l){
i1++;
continue;
}
if (i1<sz(p.sf)&&a[p.sf[i1].r]<=v.val){
v.val+=p.sf[i1].sum;
v.l=p.sf[i1].l;
i1++;
continue;
}
if (i2<sz(q.pf)&&a[q.pf[i2].l]<=v.val){
v.val+=q.pf[i2].sum;
v.r=q.pf[i2].r;
i2++;
continue;
}
break;
}
}
if (v.l==r.l||v.r==r.r)temp.pb(v);
}
for (auto u:q.tmp){
auto v=u;
if (v.l==q.l){
int i1=0,i2=0;
while (true){
if (i1<sz(q.pf)&&v.r>=q.pf[i1].r){
i1++;
continue;
}
if (i1<sz(q.pf)&&a[q.pf[i1].l]<=v.val){
v.val+=q.pf[i1].sum;
v.r=q.pf[i1].r;
i1++;
continue;
}
if (i2<sz(p.sf)&&a[p.sf[i2].r]<=v.val){
v.val+=p.sf[i2].sum;
v.l=p.sf[i2].l;
i2++;
continue;
}
break;
}
}
if (v.l==r.l||v.r==r.r)temp.pb(v);
}
sort(all(temp));
while (!temp.empty()){
auto u=temp.back();
temp.pop_back();
if (r.tmp.empty()){
r.tmp.pb(u);
continue;
}
if (r.tmp.back().l==u.l&&r.tmp.back().r==u.r){
r.tmp.back().num+=u.num;
continue;
}
r.tmp.pb(u);
}
return r;
}
void build(int id,int l,int r){
if (l==r){
st[id].l=l,st[id].r=r;
st[id].sum=a[l];
st[id].pf.pb({l,l,a[l]}),st[id].sf.pb({l,l,a[l]});
st[id].tmp.pb({l,l,1,a[l]});
return;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
st[id]=merge(st[id<<1],st[id<<1|1]);
}
void update(int id,int l,int r,int u,int val){
if (l>u||r<u)return;
if (l==r){
st[id].sum=val;
st[id].pf.clear(),st[id].sf.clear(),st[id].tmp.clear();
st[id].pf.pb({l,l,a[l]}),st[id].sf.pb({l,l,a[l]});
st[id].tmp.pb({l,l,1,a[l]});
return;
}
int mid=(l+r)>>1;
update(id<<1,l,mid,u,val);
update(id<<1|1,mid+1,r,u,val);
st[id]=merge(st[id<<1],st[id<<1|1]);
}
node get(int id,int l,int r,int u,int v){
if (l>v||r<u||u>v)return node();
if (u<=l&&r<=v)return st[id];
int mid=(l+r)>>1;
return merge(get(id<<1,l,mid,u,v),get(id<<1|1,mid+1,r,u,v));
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int n;
    cin>>n;
    for1(i,1,n)cin>>a[i];
    build(1,1,n);
    int q;
    cin>>q;
    for1(i,1,q){
    int t;
    cin>>t;
    if (t==1){
    int x,y;
    cin>>x>>y;
    a[x]=y;
    update(1,1,n,x,y);
    }
    else {
    int l,r;
    cin>>l>>r;
    node tmp=get(1,1,n,l,r);
    for (auto v:tmp.tmp){
    if (v.l==l&&v.r==r){
    cout<<v.num<<'\n';
    }
    }
    }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 35416 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 7 ms 35420 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 13 ms 35760 KB Output is correct
6 Correct 13 ms 35676 KB Output is correct
7 Correct 11 ms 35676 KB Output is correct
8 Correct 10 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 11 ms 35420 KB Output is correct
11 Correct 9 ms 35420 KB Output is correct
12 Correct 9 ms 35672 KB Output is correct
13 Correct 10 ms 35676 KB Output is correct
14 Correct 13 ms 35744 KB Output is correct
15 Correct 10 ms 35676 KB Output is correct
16 Correct 12 ms 35676 KB Output is correct
17 Correct 9 ms 35524 KB Output is correct
18 Correct 11 ms 35928 KB Output is correct
19 Correct 9 ms 35676 KB Output is correct
20 Correct 10 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 99 ms 74572 KB Output is correct
3 Correct 98 ms 71252 KB Output is correct
4 Correct 96 ms 74324 KB Output is correct
5 Correct 95 ms 71664 KB Output is correct
6 Correct 84 ms 61780 KB Output is correct
7 Correct 81 ms 61204 KB Output is correct
8 Correct 83 ms 61568 KB Output is correct
9 Correct 87 ms 61228 KB Output is correct
10 Correct 106 ms 75604 KB Output is correct
11 Correct 95 ms 68436 KB Output is correct
12 Correct 83 ms 60448 KB Output is correct
13 Correct 91 ms 60468 KB Output is correct
14 Correct 92 ms 63572 KB Output is correct
15 Correct 89 ms 63940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 35416 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 7 ms 35420 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 13 ms 35760 KB Output is correct
6 Correct 13 ms 35676 KB Output is correct
7 Correct 11 ms 35676 KB Output is correct
8 Correct 10 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 11 ms 35420 KB Output is correct
11 Correct 9 ms 35420 KB Output is correct
12 Correct 9 ms 35672 KB Output is correct
13 Correct 10 ms 35676 KB Output is correct
14 Correct 13 ms 35744 KB Output is correct
15 Correct 10 ms 35676 KB Output is correct
16 Correct 12 ms 35676 KB Output is correct
17 Correct 9 ms 35524 KB Output is correct
18 Correct 11 ms 35928 KB Output is correct
19 Correct 9 ms 35676 KB Output is correct
20 Correct 10 ms 35676 KB Output is correct
21 Correct 7 ms 35420 KB Output is correct
22 Correct 99 ms 74572 KB Output is correct
23 Correct 98 ms 71252 KB Output is correct
24 Correct 96 ms 74324 KB Output is correct
25 Correct 95 ms 71664 KB Output is correct
26 Correct 84 ms 61780 KB Output is correct
27 Correct 81 ms 61204 KB Output is correct
28 Correct 83 ms 61568 KB Output is correct
29 Correct 87 ms 61228 KB Output is correct
30 Correct 106 ms 75604 KB Output is correct
31 Correct 95 ms 68436 KB Output is correct
32 Correct 83 ms 60448 KB Output is correct
33 Correct 91 ms 60468 KB Output is correct
34 Correct 92 ms 63572 KB Output is correct
35 Correct 89 ms 63940 KB Output is correct
36 Correct 136 ms 74596 KB Output is correct
37 Correct 125 ms 71504 KB Output is correct
38 Correct 118 ms 71316 KB Output is correct
39 Correct 125 ms 74440 KB Output is correct
40 Correct 118 ms 71336 KB Output is correct
41 Correct 113 ms 61820 KB Output is correct
42 Correct 90 ms 61780 KB Output is correct
43 Correct 119 ms 61396 KB Output is correct
44 Correct 97 ms 61120 KB Output is correct
45 Correct 132 ms 75600 KB Output is correct
46 Correct 131 ms 75840 KB Output is correct
47 Correct 119 ms 66904 KB Output is correct
48 Correct 91 ms 60960 KB Output is correct
49 Correct 87 ms 60496 KB Output is correct
50 Correct 93 ms 63320 KB Output is correct
51 Correct 97 ms 63784 KB Output is correct
52 Correct 96 ms 63312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 99 ms 74572 KB Output is correct
3 Correct 98 ms 71252 KB Output is correct
4 Correct 96 ms 74324 KB Output is correct
5 Correct 95 ms 71664 KB Output is correct
6 Correct 84 ms 61780 KB Output is correct
7 Correct 81 ms 61204 KB Output is correct
8 Correct 83 ms 61568 KB Output is correct
9 Correct 87 ms 61228 KB Output is correct
10 Correct 106 ms 75604 KB Output is correct
11 Correct 95 ms 68436 KB Output is correct
12 Correct 83 ms 60448 KB Output is correct
13 Correct 91 ms 60468 KB Output is correct
14 Correct 92 ms 63572 KB Output is correct
15 Correct 89 ms 63940 KB Output is correct
16 Correct 7 ms 35420 KB Output is correct
17 Correct 2331 ms 73264 KB Output is correct
18 Correct 1873 ms 76440 KB Output is correct
19 Correct 2313 ms 73588 KB Output is correct
20 Correct 2350 ms 72808 KB Output is correct
21 Correct 2328 ms 73024 KB Output is correct
22 Correct 1838 ms 76440 KB Output is correct
23 Correct 2300 ms 72712 KB Output is correct
24 Correct 2328 ms 73556 KB Output is correct
25 Correct 2308 ms 73348 KB Output is correct
26 Correct 2329 ms 73160 KB Output is correct
27 Correct 936 ms 63624 KB Output is correct
28 Correct 866 ms 64140 KB Output is correct
29 Correct 941 ms 63764 KB Output is correct
30 Correct 1344 ms 62980 KB Output is correct
31 Correct 1373 ms 62928 KB Output is correct
32 Correct 2663 ms 69592 KB Output is correct
33 Correct 2630 ms 77924 KB Output is correct
34 Correct 2695 ms 69376 KB Output is correct
35 Correct 2536 ms 67828 KB Output is correct
36 Correct 2866 ms 77392 KB Output is correct
37 Correct 899 ms 62040 KB Output is correct
38 Correct 833 ms 61980 KB Output is correct
39 Correct 1103 ms 65108 KB Output is correct
40 Correct 1193 ms 65652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 35420 KB Output is correct
2 Correct 99 ms 74572 KB Output is correct
3 Correct 98 ms 71252 KB Output is correct
4 Correct 96 ms 74324 KB Output is correct
5 Correct 95 ms 71664 KB Output is correct
6 Correct 84 ms 61780 KB Output is correct
7 Correct 81 ms 61204 KB Output is correct
8 Correct 83 ms 61568 KB Output is correct
9 Correct 87 ms 61228 KB Output is correct
10 Correct 106 ms 75604 KB Output is correct
11 Correct 95 ms 68436 KB Output is correct
12 Correct 83 ms 60448 KB Output is correct
13 Correct 91 ms 60468 KB Output is correct
14 Correct 92 ms 63572 KB Output is correct
15 Correct 89 ms 63940 KB Output is correct
16 Correct 7 ms 35416 KB Output is correct
17 Correct 2120 ms 76008 KB Output is correct
18 Correct 1270 ms 73552 KB Output is correct
19 Correct 1620 ms 72660 KB Output is correct
20 Correct 932 ms 73544 KB Output is correct
21 Correct 1850 ms 75480 KB Output is correct
22 Correct 1308 ms 73552 KB Output is correct
23 Correct 1838 ms 72528 KB Output is correct
24 Correct 1139 ms 73768 KB Output is correct
25 Correct 1686 ms 72420 KB Output is correct
26 Correct 630 ms 63568 KB Output is correct
27 Correct 800 ms 63564 KB Output is correct
28 Correct 870 ms 65908 KB Output is correct
29 Correct 675 ms 63716 KB Output is correct
30 Correct 826 ms 63568 KB Output is correct
31 Correct 1036 ms 66268 KB Output is correct
32 Correct 1207 ms 71196 KB Output is correct
33 Correct 1595 ms 69776 KB Output is correct
34 Correct 1099 ms 77312 KB Output is correct
35 Correct 1622 ms 77272 KB Output is correct
36 Correct 1027 ms 69772 KB Output is correct
37 Correct 930 ms 66680 KB Output is correct
38 Correct 560 ms 66192 KB Output is correct
39 Correct 680 ms 65560 KB Output is correct
40 Correct 311 ms 65628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 35416 KB Output is correct
2 Correct 7 ms 35420 KB Output is correct
3 Correct 7 ms 35420 KB Output is correct
4 Correct 7 ms 35420 KB Output is correct
5 Correct 13 ms 35760 KB Output is correct
6 Correct 13 ms 35676 KB Output is correct
7 Correct 11 ms 35676 KB Output is correct
8 Correct 10 ms 35676 KB Output is correct
9 Correct 14 ms 35672 KB Output is correct
10 Correct 11 ms 35420 KB Output is correct
11 Correct 9 ms 35420 KB Output is correct
12 Correct 9 ms 35672 KB Output is correct
13 Correct 10 ms 35676 KB Output is correct
14 Correct 13 ms 35744 KB Output is correct
15 Correct 10 ms 35676 KB Output is correct
16 Correct 12 ms 35676 KB Output is correct
17 Correct 9 ms 35524 KB Output is correct
18 Correct 11 ms 35928 KB Output is correct
19 Correct 9 ms 35676 KB Output is correct
20 Correct 10 ms 35676 KB Output is correct
21 Correct 7 ms 35420 KB Output is correct
22 Correct 99 ms 74572 KB Output is correct
23 Correct 98 ms 71252 KB Output is correct
24 Correct 96 ms 74324 KB Output is correct
25 Correct 95 ms 71664 KB Output is correct
26 Correct 84 ms 61780 KB Output is correct
27 Correct 81 ms 61204 KB Output is correct
28 Correct 83 ms 61568 KB Output is correct
29 Correct 87 ms 61228 KB Output is correct
30 Correct 106 ms 75604 KB Output is correct
31 Correct 95 ms 68436 KB Output is correct
32 Correct 83 ms 60448 KB Output is correct
33 Correct 91 ms 60468 KB Output is correct
34 Correct 92 ms 63572 KB Output is correct
35 Correct 89 ms 63940 KB Output is correct
36 Correct 136 ms 74596 KB Output is correct
37 Correct 125 ms 71504 KB Output is correct
38 Correct 118 ms 71316 KB Output is correct
39 Correct 125 ms 74440 KB Output is correct
40 Correct 118 ms 71336 KB Output is correct
41 Correct 113 ms 61820 KB Output is correct
42 Correct 90 ms 61780 KB Output is correct
43 Correct 119 ms 61396 KB Output is correct
44 Correct 97 ms 61120 KB Output is correct
45 Correct 132 ms 75600 KB Output is correct
46 Correct 131 ms 75840 KB Output is correct
47 Correct 119 ms 66904 KB Output is correct
48 Correct 91 ms 60960 KB Output is correct
49 Correct 87 ms 60496 KB Output is correct
50 Correct 93 ms 63320 KB Output is correct
51 Correct 97 ms 63784 KB Output is correct
52 Correct 96 ms 63312 KB Output is correct
53 Correct 7 ms 35420 KB Output is correct
54 Correct 2331 ms 73264 KB Output is correct
55 Correct 1873 ms 76440 KB Output is correct
56 Correct 2313 ms 73588 KB Output is correct
57 Correct 2350 ms 72808 KB Output is correct
58 Correct 2328 ms 73024 KB Output is correct
59 Correct 1838 ms 76440 KB Output is correct
60 Correct 2300 ms 72712 KB Output is correct
61 Correct 2328 ms 73556 KB Output is correct
62 Correct 2308 ms 73348 KB Output is correct
63 Correct 2329 ms 73160 KB Output is correct
64 Correct 936 ms 63624 KB Output is correct
65 Correct 866 ms 64140 KB Output is correct
66 Correct 941 ms 63764 KB Output is correct
67 Correct 1344 ms 62980 KB Output is correct
68 Correct 1373 ms 62928 KB Output is correct
69 Correct 2663 ms 69592 KB Output is correct
70 Correct 2630 ms 77924 KB Output is correct
71 Correct 2695 ms 69376 KB Output is correct
72 Correct 2536 ms 67828 KB Output is correct
73 Correct 2866 ms 77392 KB Output is correct
74 Correct 899 ms 62040 KB Output is correct
75 Correct 833 ms 61980 KB Output is correct
76 Correct 1103 ms 65108 KB Output is correct
77 Correct 1193 ms 65652 KB Output is correct
78 Correct 7 ms 35416 KB Output is correct
79 Correct 2120 ms 76008 KB Output is correct
80 Correct 1270 ms 73552 KB Output is correct
81 Correct 1620 ms 72660 KB Output is correct
82 Correct 932 ms 73544 KB Output is correct
83 Correct 1850 ms 75480 KB Output is correct
84 Correct 1308 ms 73552 KB Output is correct
85 Correct 1838 ms 72528 KB Output is correct
86 Correct 1139 ms 73768 KB Output is correct
87 Correct 1686 ms 72420 KB Output is correct
88 Correct 630 ms 63568 KB Output is correct
89 Correct 800 ms 63564 KB Output is correct
90 Correct 870 ms 65908 KB Output is correct
91 Correct 675 ms 63716 KB Output is correct
92 Correct 826 ms 63568 KB Output is correct
93 Correct 1036 ms 66268 KB Output is correct
94 Correct 1207 ms 71196 KB Output is correct
95 Correct 1595 ms 69776 KB Output is correct
96 Correct 1099 ms 77312 KB Output is correct
97 Correct 1622 ms 77272 KB Output is correct
98 Correct 1027 ms 69772 KB Output is correct
99 Correct 930 ms 66680 KB Output is correct
100 Correct 560 ms 66192 KB Output is correct
101 Correct 680 ms 65560 KB Output is correct
102 Correct 311 ms 65628 KB Output is correct
103 Correct 2432 ms 72604 KB Output is correct
104 Correct 1359 ms 76380 KB Output is correct
105 Correct 2495 ms 73600 KB Output is correct
106 Correct 1736 ms 73628 KB Output is correct
107 Correct 2356 ms 72872 KB Output is correct
108 Correct 1345 ms 76224 KB Output is correct
109 Correct 2286 ms 72712 KB Output is correct
110 Correct 1529 ms 73804 KB Output is correct
111 Correct 2475 ms 73480 KB Output is correct
112 Correct 1746 ms 73268 KB Output is correct
113 Correct 914 ms 63620 KB Output is correct
114 Correct 900 ms 63580 KB Output is correct
115 Correct 1249 ms 66388 KB Output is correct
116 Correct 1299 ms 66216 KB Output is correct
117 Correct 912 ms 63692 KB Output is correct
118 Correct 1358 ms 65820 KB Output is correct
119 Correct 961 ms 63732 KB Output is correct
120 Correct 1282 ms 66412 KB Output is correct
121 Correct 1363 ms 66320 KB Output is correct
122 Correct 1330 ms 70428 KB Output is correct
123 Correct 2451 ms 69984 KB Output is correct
124 Correct 1617 ms 68560 KB Output is correct
125 Correct 2317 ms 67476 KB Output is correct
126 Correct 1793 ms 68108 KB Output is correct
127 Correct 1256 ms 66848 KB Output is correct
128 Correct 1123 ms 64536 KB Output is correct
129 Correct 1140 ms 65752 KB Output is correct
130 Correct 1128 ms 65964 KB Output is correct