#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=1e5+10;
const ll inf=1e18;
ll n,a[M],q,ml[M],mr[M],pre[M],ans[M];
map<int,set<int>>s;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i],s[a[i]].insert(i);
ll q;
cin>>q;
while(q--){
ll type;
cin>>type;
if(type==1){
ll x,y;
cin>>x>>y;
x--;
s[a[x]].erase(x);
a[x]=y;
s[a[x]].insert(x);
continue;
}
ll l,r;
cin>>l>>r;
l--,r--;
vector<int>v;
for(int i=l;i<=r;i++){
ml[i]=mr[i]=inf;
}
for(int i=l;i<=r;i++){
while(v.size()>0&&a[i]>=a[v.back()])
v.pop_back();
if(v.size()>0)
ml[i]=v.back();
v.pb(i);
}
v.clear();
for(int i=r;i>=l;i--){
while(v.size()>0&&a[i]>=a[v.back()])
v.pop_back();
if(v.size()>0)
mr[i]=v.back();
v.pb(i);
}
pre[l]=0;
for(int i=l;i<=r;i++)
pre[i+1]=a[i]+pre[i],ans[i]=0;
ll res=0;
for(auto it=s.rbegin();it!=s.rend();it++){
for(auto itt:it->S){
if(itt>=l&&itt<=r){
if(ml[itt]==mr[itt]&&ml[itt]==inf){
ans[itt]=1,res++;
continue;
}
if(ml[itt]==inf)
ml[itt]=l-1;
if(mr[itt]==inf)
mr[itt]=r+1;
if(ml[itt]>=l&&ans[ml[itt]])
ans[itt]|=((pre[mr[itt]]-pre[ml[itt]+1])>=a[ml[itt]]);
if(mr[itt]<=r&&ans[mr[itt]]){
ans[itt]|=((pre[mr[itt]]-pre[ml[itt]+1])>=a[mr[itt]]);
}
res+=ans[itt];
}
}
}
cout<<res<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
532 KB |
Output is correct |
17 |
Correct |
2 ms |
556 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
11612 KB |
Output is correct |
3 |
Correct |
25 ms |
9568 KB |
Output is correct |
4 |
Correct |
35 ms |
11612 KB |
Output is correct |
5 |
Correct |
25 ms |
9700 KB |
Output is correct |
6 |
Correct |
59 ms |
19284 KB |
Output is correct |
7 |
Correct |
25 ms |
9308 KB |
Output is correct |
8 |
Correct |
58 ms |
19284 KB |
Output is correct |
9 |
Correct |
24 ms |
9300 KB |
Output is correct |
10 |
Correct |
32 ms |
10844 KB |
Output is correct |
11 |
Correct |
21 ms |
9308 KB |
Output is correct |
12 |
Correct |
31 ms |
9296 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
37 ms |
9556 KB |
Output is correct |
15 |
Correct |
34 ms |
9564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
532 KB |
Output is correct |
17 |
Correct |
2 ms |
556 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
476 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
35 ms |
11612 KB |
Output is correct |
23 |
Correct |
25 ms |
9568 KB |
Output is correct |
24 |
Correct |
35 ms |
11612 KB |
Output is correct |
25 |
Correct |
25 ms |
9700 KB |
Output is correct |
26 |
Correct |
59 ms |
19284 KB |
Output is correct |
27 |
Correct |
25 ms |
9308 KB |
Output is correct |
28 |
Correct |
58 ms |
19284 KB |
Output is correct |
29 |
Correct |
24 ms |
9300 KB |
Output is correct |
30 |
Correct |
32 ms |
10844 KB |
Output is correct |
31 |
Correct |
21 ms |
9308 KB |
Output is correct |
32 |
Correct |
31 ms |
9296 KB |
Output is correct |
33 |
Correct |
34 ms |
9308 KB |
Output is correct |
34 |
Correct |
37 ms |
9556 KB |
Output is correct |
35 |
Correct |
34 ms |
9564 KB |
Output is correct |
36 |
Correct |
740 ms |
9688 KB |
Output is correct |
37 |
Correct |
1499 ms |
9700 KB |
Output is correct |
38 |
Correct |
1811 ms |
9816 KB |
Output is correct |
39 |
Correct |
329 ms |
9556 KB |
Output is correct |
40 |
Correct |
1919 ms |
9816 KB |
Output is correct |
41 |
Correct |
3549 ms |
19288 KB |
Output is correct |
42 |
Execution timed out |
4074 ms |
19288 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
11612 KB |
Output is correct |
3 |
Correct |
25 ms |
9568 KB |
Output is correct |
4 |
Correct |
35 ms |
11612 KB |
Output is correct |
5 |
Correct |
25 ms |
9700 KB |
Output is correct |
6 |
Correct |
59 ms |
19284 KB |
Output is correct |
7 |
Correct |
25 ms |
9308 KB |
Output is correct |
8 |
Correct |
58 ms |
19284 KB |
Output is correct |
9 |
Correct |
24 ms |
9300 KB |
Output is correct |
10 |
Correct |
32 ms |
10844 KB |
Output is correct |
11 |
Correct |
21 ms |
9308 KB |
Output is correct |
12 |
Correct |
31 ms |
9296 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
37 ms |
9556 KB |
Output is correct |
15 |
Correct |
34 ms |
9564 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4088 ms |
9768 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
11612 KB |
Output is correct |
3 |
Correct |
25 ms |
9568 KB |
Output is correct |
4 |
Correct |
35 ms |
11612 KB |
Output is correct |
5 |
Correct |
25 ms |
9700 KB |
Output is correct |
6 |
Correct |
59 ms |
19284 KB |
Output is correct |
7 |
Correct |
25 ms |
9308 KB |
Output is correct |
8 |
Correct |
58 ms |
19284 KB |
Output is correct |
9 |
Correct |
24 ms |
9300 KB |
Output is correct |
10 |
Correct |
32 ms |
10844 KB |
Output is correct |
11 |
Correct |
21 ms |
9308 KB |
Output is correct |
12 |
Correct |
31 ms |
9296 KB |
Output is correct |
13 |
Correct |
34 ms |
9308 KB |
Output is correct |
14 |
Correct |
37 ms |
9556 KB |
Output is correct |
15 |
Correct |
34 ms |
9564 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4091 ms |
12084 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
5 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
532 KB |
Output is correct |
17 |
Correct |
2 ms |
556 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
476 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
35 ms |
11612 KB |
Output is correct |
23 |
Correct |
25 ms |
9568 KB |
Output is correct |
24 |
Correct |
35 ms |
11612 KB |
Output is correct |
25 |
Correct |
25 ms |
9700 KB |
Output is correct |
26 |
Correct |
59 ms |
19284 KB |
Output is correct |
27 |
Correct |
25 ms |
9308 KB |
Output is correct |
28 |
Correct |
58 ms |
19284 KB |
Output is correct |
29 |
Correct |
24 ms |
9300 KB |
Output is correct |
30 |
Correct |
32 ms |
10844 KB |
Output is correct |
31 |
Correct |
21 ms |
9308 KB |
Output is correct |
32 |
Correct |
31 ms |
9296 KB |
Output is correct |
33 |
Correct |
34 ms |
9308 KB |
Output is correct |
34 |
Correct |
37 ms |
9556 KB |
Output is correct |
35 |
Correct |
34 ms |
9564 KB |
Output is correct |
36 |
Correct |
740 ms |
9688 KB |
Output is correct |
37 |
Correct |
1499 ms |
9700 KB |
Output is correct |
38 |
Correct |
1811 ms |
9816 KB |
Output is correct |
39 |
Correct |
329 ms |
9556 KB |
Output is correct |
40 |
Correct |
1919 ms |
9816 KB |
Output is correct |
41 |
Correct |
3549 ms |
19288 KB |
Output is correct |
42 |
Execution timed out |
4074 ms |
19288 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |