#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
int arr[100005];
int prefix[100005];
void solve(){
int n;
cin >> n;
int lft[n+5];
int rgt[n+5];
for(int x=1;x<=n;x++){
cin >> arr[x];
}
int q;
cin >> q;
int temp,l,r;
for(int x=0;x<q;x++){
cin >> temp >> l >> r;
if(temp==1) arr[l]=r;
else{
prefix[l-1]=0;
for(int y=l;y<=r;y++){
prefix[y]=prefix[y-1]+arr[y];
lft[y]=rgt[y]=y;
}
int counter=0;
for(int y=l;y<=r;y++){
while(lft[y]>l||rgt[y]<r){
if(lft[y]>l&&prefix[rgt[y]]-prefix[lft[y]-1]>=arr[lft[y]-1]){
int hold=lft[y]-1;
lft[y]=min(lft[y],lft[hold]);
rgt[y]=max(rgt[y],rgt[hold]);
}
else if(rgt[y]<r&&prefix[rgt[y]]-prefix[lft[y]-1]>=arr[rgt[y]+1]){
int hold=rgt[y]+1;
lft[y]=min(lft[y],lft[hold]);
rgt[y]=max(rgt[y],rgt[hold]);
}
else break;
}
if(lft[y]==l&&rgt[y]==r) counter++;
}
cout << counter << "\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
//freopen("in.txt","r",stdin);
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
3932 KB |
Output is correct |
3 |
Correct |
8 ms |
3892 KB |
Output is correct |
4 |
Correct |
8 ms |
3940 KB |
Output is correct |
5 |
Correct |
8 ms |
3676 KB |
Output is correct |
6 |
Correct |
9 ms |
4536 KB |
Output is correct |
7 |
Correct |
8 ms |
3676 KB |
Output is correct |
8 |
Correct |
10 ms |
4556 KB |
Output is correct |
9 |
Correct |
8 ms |
3792 KB |
Output is correct |
10 |
Correct |
11 ms |
4172 KB |
Output is correct |
11 |
Correct |
13 ms |
3672 KB |
Output is correct |
12 |
Correct |
8 ms |
3832 KB |
Output is correct |
13 |
Correct |
8 ms |
3672 KB |
Output is correct |
14 |
Correct |
8 ms |
4016 KB |
Output is correct |
15 |
Correct |
9 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
8 ms |
3932 KB |
Output is correct |
23 |
Correct |
8 ms |
3892 KB |
Output is correct |
24 |
Correct |
8 ms |
3940 KB |
Output is correct |
25 |
Correct |
8 ms |
3676 KB |
Output is correct |
26 |
Correct |
9 ms |
4536 KB |
Output is correct |
27 |
Correct |
8 ms |
3676 KB |
Output is correct |
28 |
Correct |
10 ms |
4556 KB |
Output is correct |
29 |
Correct |
8 ms |
3792 KB |
Output is correct |
30 |
Correct |
11 ms |
4172 KB |
Output is correct |
31 |
Correct |
13 ms |
3672 KB |
Output is correct |
32 |
Correct |
8 ms |
3832 KB |
Output is correct |
33 |
Correct |
8 ms |
3672 KB |
Output is correct |
34 |
Correct |
8 ms |
4016 KB |
Output is correct |
35 |
Correct |
9 ms |
4188 KB |
Output is correct |
36 |
Correct |
135 ms |
3928 KB |
Output is correct |
37 |
Correct |
408 ms |
3920 KB |
Output is correct |
38 |
Correct |
483 ms |
3676 KB |
Output is correct |
39 |
Correct |
57 ms |
3928 KB |
Output is correct |
40 |
Correct |
526 ms |
3896 KB |
Output is correct |
41 |
Correct |
288 ms |
4444 KB |
Output is correct |
42 |
Correct |
369 ms |
4444 KB |
Output is correct |
43 |
Correct |
554 ms |
3676 KB |
Output is correct |
44 |
Correct |
660 ms |
3676 KB |
Output is correct |
45 |
Correct |
608 ms |
4176 KB |
Output is correct |
46 |
Correct |
839 ms |
4180 KB |
Output is correct |
47 |
Correct |
1437 ms |
3672 KB |
Output is correct |
48 |
Correct |
159 ms |
3828 KB |
Output is correct |
49 |
Correct |
500 ms |
3728 KB |
Output is correct |
50 |
Correct |
217 ms |
4184 KB |
Output is correct |
51 |
Correct |
958 ms |
4188 KB |
Output is correct |
52 |
Correct |
1022 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
3932 KB |
Output is correct |
3 |
Correct |
8 ms |
3892 KB |
Output is correct |
4 |
Correct |
8 ms |
3940 KB |
Output is correct |
5 |
Correct |
8 ms |
3676 KB |
Output is correct |
6 |
Correct |
9 ms |
4536 KB |
Output is correct |
7 |
Correct |
8 ms |
3676 KB |
Output is correct |
8 |
Correct |
10 ms |
4556 KB |
Output is correct |
9 |
Correct |
8 ms |
3792 KB |
Output is correct |
10 |
Correct |
11 ms |
4172 KB |
Output is correct |
11 |
Correct |
13 ms |
3672 KB |
Output is correct |
12 |
Correct |
8 ms |
3832 KB |
Output is correct |
13 |
Correct |
8 ms |
3672 KB |
Output is correct |
14 |
Correct |
8 ms |
4016 KB |
Output is correct |
15 |
Correct |
9 ms |
4188 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4088 ms |
4204 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
3932 KB |
Output is correct |
3 |
Correct |
8 ms |
3892 KB |
Output is correct |
4 |
Correct |
8 ms |
3940 KB |
Output is correct |
5 |
Correct |
8 ms |
3676 KB |
Output is correct |
6 |
Correct |
9 ms |
4536 KB |
Output is correct |
7 |
Correct |
8 ms |
3676 KB |
Output is correct |
8 |
Correct |
10 ms |
4556 KB |
Output is correct |
9 |
Correct |
8 ms |
3792 KB |
Output is correct |
10 |
Correct |
11 ms |
4172 KB |
Output is correct |
11 |
Correct |
13 ms |
3672 KB |
Output is correct |
12 |
Correct |
8 ms |
3832 KB |
Output is correct |
13 |
Correct |
8 ms |
3672 KB |
Output is correct |
14 |
Correct |
8 ms |
4016 KB |
Output is correct |
15 |
Correct |
9 ms |
4188 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4066 ms |
4572 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
8 ms |
3932 KB |
Output is correct |
23 |
Correct |
8 ms |
3892 KB |
Output is correct |
24 |
Correct |
8 ms |
3940 KB |
Output is correct |
25 |
Correct |
8 ms |
3676 KB |
Output is correct |
26 |
Correct |
9 ms |
4536 KB |
Output is correct |
27 |
Correct |
8 ms |
3676 KB |
Output is correct |
28 |
Correct |
10 ms |
4556 KB |
Output is correct |
29 |
Correct |
8 ms |
3792 KB |
Output is correct |
30 |
Correct |
11 ms |
4172 KB |
Output is correct |
31 |
Correct |
13 ms |
3672 KB |
Output is correct |
32 |
Correct |
8 ms |
3832 KB |
Output is correct |
33 |
Correct |
8 ms |
3672 KB |
Output is correct |
34 |
Correct |
8 ms |
4016 KB |
Output is correct |
35 |
Correct |
9 ms |
4188 KB |
Output is correct |
36 |
Correct |
135 ms |
3928 KB |
Output is correct |
37 |
Correct |
408 ms |
3920 KB |
Output is correct |
38 |
Correct |
483 ms |
3676 KB |
Output is correct |
39 |
Correct |
57 ms |
3928 KB |
Output is correct |
40 |
Correct |
526 ms |
3896 KB |
Output is correct |
41 |
Correct |
288 ms |
4444 KB |
Output is correct |
42 |
Correct |
369 ms |
4444 KB |
Output is correct |
43 |
Correct |
554 ms |
3676 KB |
Output is correct |
44 |
Correct |
660 ms |
3676 KB |
Output is correct |
45 |
Correct |
608 ms |
4176 KB |
Output is correct |
46 |
Correct |
839 ms |
4180 KB |
Output is correct |
47 |
Correct |
1437 ms |
3672 KB |
Output is correct |
48 |
Correct |
159 ms |
3828 KB |
Output is correct |
49 |
Correct |
500 ms |
3728 KB |
Output is correct |
50 |
Correct |
217 ms |
4184 KB |
Output is correct |
51 |
Correct |
958 ms |
4188 KB |
Output is correct |
52 |
Correct |
1022 ms |
4188 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Execution timed out |
4088 ms |
4204 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |