#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m;
int val[mxn+10],put[mxn+10],pref[mxn+10];
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
void solve(int l,int r){
stack<int>st,st2;
int tmp=val[l-1];
val[l-1]=inf;
st.push(l-1);
st2.push(l-1);
pref[l-1]=put[l-1]=0;
for(int i=l;i<=r;i++){
pref[i]=val[i]+pref[i-1];
put[i]=0;
while(val[i]>val[st.top()])st.pop();
if(pref[i-1]-pref[st.top()]<val[i])put[st.top()+1]++,put[i]--;
while(val[i]>=val[st2.top()]){
if(pref[i-1]-pref[st2.top()]<val[st2.top()])put[st2.top()+1]++,put[i]--;
st2.pop();
}
st.push(i);
st2.push(i);
}
while(!st2.empty()){
if(st2.top()!=l-1&&pref[r]-pref[st2.top()]<val[st2.top()]){
put[st2.top()+1]++;
}
st2.pop();
}
val[l-1]=tmp;
int ans=0;
for(int i=l;i<=r;i++){
put[i]+=put[i-1],ans+=(!put[i]);
}
cout<<ans<<'\n';
}
int32_t main(){
fastio
//brute force check
cin>>n;
for(int i=1;i<=n;i++)cin>>val[i];
int q;cin>>q;
while(q--){
int t,x,y;cin>>t>>x>>y;
if(t==1)val[x]=y;
else solve(x,y);
}
}
/*
each element will be bounded by range l,r
where sum(l+1,r-1)<minval(l,r)
then every element in range l,r cant go out of range l,r
range where x is one of the bound can be found
by finding the first left and right pos y where val[y]>=val[x]
because if val[a]>=x and a<y
then range (a,y) will also cover if range (a,l) cover
we can update range and find y for the updated x by bin search+seg tree
how do we answer?
let ql,qr be the queried range
we have list of bounded range(l,r)
if l,r is in ql,qr or l,r intersect with ql,qr then we can still use that l,r
but if l,r cover ql,qr then we can use that l,r?
*/
Compilation message
fish2.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
fish2.cpp:39:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
39 | void setIO(string name){
| ^
fish2.cpp:44:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
44 | void solve(int l,int r){
| ^
fish2.cpp:76:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
76 | int32_t main(){
| ^
fish2.cpp: In function 'void setIO(std::string)':
fish2.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish2.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
3308 KB |
Output is correct |
3 |
Correct |
6 ms |
2908 KB |
Output is correct |
4 |
Correct |
7 ms |
3164 KB |
Output is correct |
5 |
Correct |
5 ms |
3132 KB |
Output is correct |
6 |
Correct |
9 ms |
3672 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
9 ms |
3724 KB |
Output is correct |
9 |
Correct |
6 ms |
2908 KB |
Output is correct |
10 |
Correct |
7 ms |
3164 KB |
Output is correct |
11 |
Correct |
6 ms |
2928 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
7 ms |
2908 KB |
Output is correct |
14 |
Correct |
8 ms |
3288 KB |
Output is correct |
15 |
Correct |
8 ms |
3308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
3308 KB |
Output is correct |
23 |
Correct |
6 ms |
2908 KB |
Output is correct |
24 |
Correct |
7 ms |
3164 KB |
Output is correct |
25 |
Correct |
5 ms |
3132 KB |
Output is correct |
26 |
Correct |
9 ms |
3672 KB |
Output is correct |
27 |
Correct |
6 ms |
2908 KB |
Output is correct |
28 |
Correct |
9 ms |
3724 KB |
Output is correct |
29 |
Correct |
6 ms |
2908 KB |
Output is correct |
30 |
Correct |
7 ms |
3164 KB |
Output is correct |
31 |
Correct |
6 ms |
2928 KB |
Output is correct |
32 |
Correct |
6 ms |
2908 KB |
Output is correct |
33 |
Correct |
7 ms |
2908 KB |
Output is correct |
34 |
Correct |
8 ms |
3288 KB |
Output is correct |
35 |
Correct |
8 ms |
3308 KB |
Output is correct |
36 |
Correct |
132 ms |
3164 KB |
Output is correct |
37 |
Correct |
202 ms |
2908 KB |
Output is correct |
38 |
Correct |
246 ms |
2908 KB |
Output is correct |
39 |
Correct |
57 ms |
3420 KB |
Output is correct |
40 |
Correct |
248 ms |
3152 KB |
Output is correct |
41 |
Correct |
322 ms |
3920 KB |
Output is correct |
42 |
Correct |
439 ms |
3756 KB |
Output is correct |
43 |
Correct |
365 ms |
2904 KB |
Output is correct |
44 |
Correct |
431 ms |
2896 KB |
Output is correct |
45 |
Correct |
132 ms |
3164 KB |
Output is correct |
46 |
Correct |
203 ms |
3160 KB |
Output is correct |
47 |
Correct |
246 ms |
2904 KB |
Output is correct |
48 |
Correct |
135 ms |
2872 KB |
Output is correct |
49 |
Correct |
437 ms |
3160 KB |
Output is correct |
50 |
Correct |
208 ms |
3436 KB |
Output is correct |
51 |
Correct |
896 ms |
3452 KB |
Output is correct |
52 |
Correct |
967 ms |
3664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
3308 KB |
Output is correct |
3 |
Correct |
6 ms |
2908 KB |
Output is correct |
4 |
Correct |
7 ms |
3164 KB |
Output is correct |
5 |
Correct |
5 ms |
3132 KB |
Output is correct |
6 |
Correct |
9 ms |
3672 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
9 ms |
3724 KB |
Output is correct |
9 |
Correct |
6 ms |
2908 KB |
Output is correct |
10 |
Correct |
7 ms |
3164 KB |
Output is correct |
11 |
Correct |
6 ms |
2928 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
7 ms |
2908 KB |
Output is correct |
14 |
Correct |
8 ms |
3288 KB |
Output is correct |
15 |
Correct |
8 ms |
3308 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4066 ms |
3412 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
3308 KB |
Output is correct |
3 |
Correct |
6 ms |
2908 KB |
Output is correct |
4 |
Correct |
7 ms |
3164 KB |
Output is correct |
5 |
Correct |
5 ms |
3132 KB |
Output is correct |
6 |
Correct |
9 ms |
3672 KB |
Output is correct |
7 |
Correct |
6 ms |
2908 KB |
Output is correct |
8 |
Correct |
9 ms |
3724 KB |
Output is correct |
9 |
Correct |
6 ms |
2908 KB |
Output is correct |
10 |
Correct |
7 ms |
3164 KB |
Output is correct |
11 |
Correct |
6 ms |
2928 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
7 ms |
2908 KB |
Output is correct |
14 |
Correct |
8 ms |
3288 KB |
Output is correct |
15 |
Correct |
8 ms |
3308 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4081 ms |
3936 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
7 ms |
3308 KB |
Output is correct |
23 |
Correct |
6 ms |
2908 KB |
Output is correct |
24 |
Correct |
7 ms |
3164 KB |
Output is correct |
25 |
Correct |
5 ms |
3132 KB |
Output is correct |
26 |
Correct |
9 ms |
3672 KB |
Output is correct |
27 |
Correct |
6 ms |
2908 KB |
Output is correct |
28 |
Correct |
9 ms |
3724 KB |
Output is correct |
29 |
Correct |
6 ms |
2908 KB |
Output is correct |
30 |
Correct |
7 ms |
3164 KB |
Output is correct |
31 |
Correct |
6 ms |
2928 KB |
Output is correct |
32 |
Correct |
6 ms |
2908 KB |
Output is correct |
33 |
Correct |
7 ms |
2908 KB |
Output is correct |
34 |
Correct |
8 ms |
3288 KB |
Output is correct |
35 |
Correct |
8 ms |
3308 KB |
Output is correct |
36 |
Correct |
132 ms |
3164 KB |
Output is correct |
37 |
Correct |
202 ms |
2908 KB |
Output is correct |
38 |
Correct |
246 ms |
2908 KB |
Output is correct |
39 |
Correct |
57 ms |
3420 KB |
Output is correct |
40 |
Correct |
248 ms |
3152 KB |
Output is correct |
41 |
Correct |
322 ms |
3920 KB |
Output is correct |
42 |
Correct |
439 ms |
3756 KB |
Output is correct |
43 |
Correct |
365 ms |
2904 KB |
Output is correct |
44 |
Correct |
431 ms |
2896 KB |
Output is correct |
45 |
Correct |
132 ms |
3164 KB |
Output is correct |
46 |
Correct |
203 ms |
3160 KB |
Output is correct |
47 |
Correct |
246 ms |
2904 KB |
Output is correct |
48 |
Correct |
135 ms |
2872 KB |
Output is correct |
49 |
Correct |
437 ms |
3160 KB |
Output is correct |
50 |
Correct |
208 ms |
3436 KB |
Output is correct |
51 |
Correct |
896 ms |
3452 KB |
Output is correct |
52 |
Correct |
967 ms |
3664 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Execution timed out |
4066 ms |
3412 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |