#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 int M=1e5+10;
const int inf=1e9+10;
int n,a[M],q,ml[M],mr[M];
ll pre[M];
bool 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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 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 |
524 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
352 KB |
Output is correct |
11 |
Correct |
7 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
352 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9824 KB |
Output is correct |
3 |
Correct |
22 ms |
7776 KB |
Output is correct |
4 |
Correct |
43 ms |
9812 KB |
Output is correct |
5 |
Correct |
23 ms |
8016 KB |
Output is correct |
6 |
Correct |
54 ms |
17484 KB |
Output is correct |
7 |
Correct |
21 ms |
7252 KB |
Output is correct |
8 |
Correct |
56 ms |
17488 KB |
Output is correct |
9 |
Correct |
25 ms |
7248 KB |
Output is correct |
10 |
Correct |
33 ms |
9020 KB |
Output is correct |
11 |
Correct |
17 ms |
7532 KB |
Output is correct |
12 |
Correct |
25 ms |
7448 KB |
Output is correct |
13 |
Correct |
25 ms |
7248 KB |
Output is correct |
14 |
Correct |
26 ms |
7588 KB |
Output is correct |
15 |
Correct |
27 ms |
7764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 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 |
524 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
352 KB |
Output is correct |
11 |
Correct |
7 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
352 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
352 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
33 ms |
9824 KB |
Output is correct |
23 |
Correct |
22 ms |
7776 KB |
Output is correct |
24 |
Correct |
43 ms |
9812 KB |
Output is correct |
25 |
Correct |
23 ms |
8016 KB |
Output is correct |
26 |
Correct |
54 ms |
17484 KB |
Output is correct |
27 |
Correct |
21 ms |
7252 KB |
Output is correct |
28 |
Correct |
56 ms |
17488 KB |
Output is correct |
29 |
Correct |
25 ms |
7248 KB |
Output is correct |
30 |
Correct |
33 ms |
9020 KB |
Output is correct |
31 |
Correct |
17 ms |
7532 KB |
Output is correct |
32 |
Correct |
25 ms |
7448 KB |
Output is correct |
33 |
Correct |
25 ms |
7248 KB |
Output is correct |
34 |
Correct |
26 ms |
7588 KB |
Output is correct |
35 |
Correct |
27 ms |
7764 KB |
Output is correct |
36 |
Correct |
721 ms |
7792 KB |
Output is correct |
37 |
Correct |
1419 ms |
7916 KB |
Output is correct |
38 |
Correct |
1909 ms |
7760 KB |
Output is correct |
39 |
Correct |
313 ms |
7760 KB |
Output is correct |
40 |
Correct |
1965 ms |
8016 KB |
Output is correct |
41 |
Correct |
3683 ms |
17580 KB |
Output is correct |
42 |
Execution timed out |
4064 ms |
17532 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9824 KB |
Output is correct |
3 |
Correct |
22 ms |
7776 KB |
Output is correct |
4 |
Correct |
43 ms |
9812 KB |
Output is correct |
5 |
Correct |
23 ms |
8016 KB |
Output is correct |
6 |
Correct |
54 ms |
17484 KB |
Output is correct |
7 |
Correct |
21 ms |
7252 KB |
Output is correct |
8 |
Correct |
56 ms |
17488 KB |
Output is correct |
9 |
Correct |
25 ms |
7248 KB |
Output is correct |
10 |
Correct |
33 ms |
9020 KB |
Output is correct |
11 |
Correct |
17 ms |
7532 KB |
Output is correct |
12 |
Correct |
25 ms |
7448 KB |
Output is correct |
13 |
Correct |
25 ms |
7248 KB |
Output is correct |
14 |
Correct |
26 ms |
7588 KB |
Output is correct |
15 |
Correct |
27 ms |
7764 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4083 ms |
8356 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9824 KB |
Output is correct |
3 |
Correct |
22 ms |
7776 KB |
Output is correct |
4 |
Correct |
43 ms |
9812 KB |
Output is correct |
5 |
Correct |
23 ms |
8016 KB |
Output is correct |
6 |
Correct |
54 ms |
17484 KB |
Output is correct |
7 |
Correct |
21 ms |
7252 KB |
Output is correct |
8 |
Correct |
56 ms |
17488 KB |
Output is correct |
9 |
Correct |
25 ms |
7248 KB |
Output is correct |
10 |
Correct |
33 ms |
9020 KB |
Output is correct |
11 |
Correct |
17 ms |
7532 KB |
Output is correct |
12 |
Correct |
25 ms |
7448 KB |
Output is correct |
13 |
Correct |
25 ms |
7248 KB |
Output is correct |
14 |
Correct |
26 ms |
7588 KB |
Output is correct |
15 |
Correct |
27 ms |
7764 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4081 ms |
10012 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 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 |
524 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
352 KB |
Output is correct |
11 |
Correct |
7 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
352 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
352 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
33 ms |
9824 KB |
Output is correct |
23 |
Correct |
22 ms |
7776 KB |
Output is correct |
24 |
Correct |
43 ms |
9812 KB |
Output is correct |
25 |
Correct |
23 ms |
8016 KB |
Output is correct |
26 |
Correct |
54 ms |
17484 KB |
Output is correct |
27 |
Correct |
21 ms |
7252 KB |
Output is correct |
28 |
Correct |
56 ms |
17488 KB |
Output is correct |
29 |
Correct |
25 ms |
7248 KB |
Output is correct |
30 |
Correct |
33 ms |
9020 KB |
Output is correct |
31 |
Correct |
17 ms |
7532 KB |
Output is correct |
32 |
Correct |
25 ms |
7448 KB |
Output is correct |
33 |
Correct |
25 ms |
7248 KB |
Output is correct |
34 |
Correct |
26 ms |
7588 KB |
Output is correct |
35 |
Correct |
27 ms |
7764 KB |
Output is correct |
36 |
Correct |
721 ms |
7792 KB |
Output is correct |
37 |
Correct |
1419 ms |
7916 KB |
Output is correct |
38 |
Correct |
1909 ms |
7760 KB |
Output is correct |
39 |
Correct |
313 ms |
7760 KB |
Output is correct |
40 |
Correct |
1965 ms |
8016 KB |
Output is correct |
41 |
Correct |
3683 ms |
17580 KB |
Output is correct |
42 |
Execution timed out |
4064 ms |
17532 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |