#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define ms memset
int main(){
ios::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n; cin>>n; vector<ll> a(n); FOR(i,0,n) cin>>a[i];
set<pair<ll,int>> A;
FOR(i,0,n) A.insert({-a[i],i});
vector<ll> pre(n+1); FOR(i,1,n+1) pre[i] = pre[i-1] + a[i-1];
stack<int> s; vi l(n), r(n), ans(n);
s.push(0); l[0]=-1;
FOR(i,1,n){
while (!s.empty()){
if (a[s.top()] <= a[i]){
s.pop();
}else break;
}
if (s.empty()) l[i]=-1;
else l[i] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
s.push(n-1); r[n-1] = n;
ROF(i,n-2,0){
while (!s.empty()){
if (a[s.top()] <= a[i]){
s.pop();
}else break;
}
if (s.empty()) r[i]=n;
else r[i] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
int q; cin>>q;
FOR(_,0,q){
int op; cin>>op;
if (op==1){
int pos, val; cin>>pos>>val; pos--;
A.erase({-a[pos],pos}); a[pos] = val; A.insert({-a[pos],pos});
FOR(i,pos+1,n+1){
pre[i] = pre[i-1] + a[i-1];
}
s.push(0); l[0]=-1;
FOR(i,1,n){
while (!s.empty()){
if (a[s.top()] <= a[i]){
s.pop();
}else break;
}
if (s.empty()) l[i]=-1;
else l[i] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
s.push(n-1); r[n-1] = n;
ROF(i,n-2,0){
while (!s.empty()){
if (a[s.top()] <= a[i]){
s.pop();
}else break;
}
if (s.empty()) r[i]=n;
else r[i] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
continue;
}
int L,R; cin>>L>>R; L--; R--;
FOR(i,L,R+1) ans[i]=0;
int answer = 0;
for (auto it = A.begin(); it != A.end(); it++){
int pos = (*it).se;
if (pos<L || R<pos) continue;
if (l[pos] < L && r[pos] > R){
ans[pos]=1; continue;
}
if (l[pos] >= L && pre[min(R+1,r[pos])]-pre[max(L,l[pos]+1)] >= a[l[pos]]) ans[pos] |= ans[l[pos]];
if (r[pos] <= R && pre[min(R+1,r[pos])]-pre[max(L,l[pos]+1)] >= a[r[pos]]) ans[pos] |= ans[r[pos]];
}
FOR(i,L,R+1) answer += ans[i];
FOR(i,L,R+1) ans[i] = 0;
cout<<answer<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 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 |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
516 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9808 KB |
Output is correct |
3 |
Correct |
29 ms |
9788 KB |
Output is correct |
4 |
Correct |
32 ms |
9812 KB |
Output is correct |
5 |
Correct |
25 ms |
9804 KB |
Output is correct |
6 |
Correct |
46 ms |
10368 KB |
Output is correct |
7 |
Correct |
30 ms |
9560 KB |
Output is correct |
8 |
Correct |
46 ms |
10320 KB |
Output is correct |
9 |
Correct |
27 ms |
9680 KB |
Output is correct |
10 |
Correct |
33 ms |
9808 KB |
Output is correct |
11 |
Correct |
22 ms |
9560 KB |
Output is correct |
12 |
Correct |
29 ms |
9564 KB |
Output is correct |
13 |
Correct |
30 ms |
9612 KB |
Output is correct |
14 |
Correct |
40 ms |
9808 KB |
Output is correct |
15 |
Correct |
36 ms |
10076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 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 |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
516 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
33 ms |
9808 KB |
Output is correct |
23 |
Correct |
29 ms |
9788 KB |
Output is correct |
24 |
Correct |
32 ms |
9812 KB |
Output is correct |
25 |
Correct |
25 ms |
9804 KB |
Output is correct |
26 |
Correct |
46 ms |
10368 KB |
Output is correct |
27 |
Correct |
30 ms |
9560 KB |
Output is correct |
28 |
Correct |
46 ms |
10320 KB |
Output is correct |
29 |
Correct |
27 ms |
9680 KB |
Output is correct |
30 |
Correct |
33 ms |
9808 KB |
Output is correct |
31 |
Correct |
22 ms |
9560 KB |
Output is correct |
32 |
Correct |
29 ms |
9564 KB |
Output is correct |
33 |
Correct |
30 ms |
9612 KB |
Output is correct |
34 |
Correct |
40 ms |
9808 KB |
Output is correct |
35 |
Correct |
36 ms |
10076 KB |
Output is correct |
36 |
Correct |
1270 ms |
10192 KB |
Output is correct |
37 |
Correct |
1784 ms |
9820 KB |
Output is correct |
38 |
Correct |
1959 ms |
9804 KB |
Output is correct |
39 |
Correct |
1049 ms |
9820 KB |
Output is correct |
40 |
Correct |
1918 ms |
9808 KB |
Output is correct |
41 |
Correct |
2855 ms |
10416 KB |
Output is correct |
42 |
Correct |
3129 ms |
10292 KB |
Output is correct |
43 |
Correct |
1771 ms |
9564 KB |
Output is correct |
44 |
Correct |
1714 ms |
9672 KB |
Output is correct |
45 |
Correct |
1535 ms |
9820 KB |
Output is correct |
46 |
Correct |
2053 ms |
10040 KB |
Output is correct |
47 |
Correct |
1466 ms |
9748 KB |
Output is correct |
48 |
Correct |
2273 ms |
9724 KB |
Output is correct |
49 |
Correct |
2206 ms |
9716 KB |
Output is correct |
50 |
Correct |
1849 ms |
10064 KB |
Output is correct |
51 |
Correct |
2501 ms |
10064 KB |
Output is correct |
52 |
Correct |
2595 ms |
10068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9808 KB |
Output is correct |
3 |
Correct |
29 ms |
9788 KB |
Output is correct |
4 |
Correct |
32 ms |
9812 KB |
Output is correct |
5 |
Correct |
25 ms |
9804 KB |
Output is correct |
6 |
Correct |
46 ms |
10368 KB |
Output is correct |
7 |
Correct |
30 ms |
9560 KB |
Output is correct |
8 |
Correct |
46 ms |
10320 KB |
Output is correct |
9 |
Correct |
27 ms |
9680 KB |
Output is correct |
10 |
Correct |
33 ms |
9808 KB |
Output is correct |
11 |
Correct |
22 ms |
9560 KB |
Output is correct |
12 |
Correct |
29 ms |
9564 KB |
Output is correct |
13 |
Correct |
30 ms |
9612 KB |
Output is correct |
14 |
Correct |
40 ms |
9808 KB |
Output is correct |
15 |
Correct |
36 ms |
10076 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Execution timed out |
4086 ms |
9796 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
9808 KB |
Output is correct |
3 |
Correct |
29 ms |
9788 KB |
Output is correct |
4 |
Correct |
32 ms |
9812 KB |
Output is correct |
5 |
Correct |
25 ms |
9804 KB |
Output is correct |
6 |
Correct |
46 ms |
10368 KB |
Output is correct |
7 |
Correct |
30 ms |
9560 KB |
Output is correct |
8 |
Correct |
46 ms |
10320 KB |
Output is correct |
9 |
Correct |
27 ms |
9680 KB |
Output is correct |
10 |
Correct |
33 ms |
9808 KB |
Output is correct |
11 |
Correct |
22 ms |
9560 KB |
Output is correct |
12 |
Correct |
29 ms |
9564 KB |
Output is correct |
13 |
Correct |
30 ms |
9612 KB |
Output is correct |
14 |
Correct |
40 ms |
9808 KB |
Output is correct |
15 |
Correct |
36 ms |
10076 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4014 ms |
10220 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 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 |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
516 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
33 ms |
9808 KB |
Output is correct |
23 |
Correct |
29 ms |
9788 KB |
Output is correct |
24 |
Correct |
32 ms |
9812 KB |
Output is correct |
25 |
Correct |
25 ms |
9804 KB |
Output is correct |
26 |
Correct |
46 ms |
10368 KB |
Output is correct |
27 |
Correct |
30 ms |
9560 KB |
Output is correct |
28 |
Correct |
46 ms |
10320 KB |
Output is correct |
29 |
Correct |
27 ms |
9680 KB |
Output is correct |
30 |
Correct |
33 ms |
9808 KB |
Output is correct |
31 |
Correct |
22 ms |
9560 KB |
Output is correct |
32 |
Correct |
29 ms |
9564 KB |
Output is correct |
33 |
Correct |
30 ms |
9612 KB |
Output is correct |
34 |
Correct |
40 ms |
9808 KB |
Output is correct |
35 |
Correct |
36 ms |
10076 KB |
Output is correct |
36 |
Correct |
1270 ms |
10192 KB |
Output is correct |
37 |
Correct |
1784 ms |
9820 KB |
Output is correct |
38 |
Correct |
1959 ms |
9804 KB |
Output is correct |
39 |
Correct |
1049 ms |
9820 KB |
Output is correct |
40 |
Correct |
1918 ms |
9808 KB |
Output is correct |
41 |
Correct |
2855 ms |
10416 KB |
Output is correct |
42 |
Correct |
3129 ms |
10292 KB |
Output is correct |
43 |
Correct |
1771 ms |
9564 KB |
Output is correct |
44 |
Correct |
1714 ms |
9672 KB |
Output is correct |
45 |
Correct |
1535 ms |
9820 KB |
Output is correct |
46 |
Correct |
2053 ms |
10040 KB |
Output is correct |
47 |
Correct |
1466 ms |
9748 KB |
Output is correct |
48 |
Correct |
2273 ms |
9724 KB |
Output is correct |
49 |
Correct |
2206 ms |
9716 KB |
Output is correct |
50 |
Correct |
1849 ms |
10064 KB |
Output is correct |
51 |
Correct |
2501 ms |
10064 KB |
Output is correct |
52 |
Correct |
2595 ms |
10068 KB |
Output is correct |
53 |
Correct |
0 ms |
460 KB |
Output is correct |
54 |
Execution timed out |
4086 ms |
9796 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |