#pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int INF = INT32_MAX;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> arr(n+1);
for(int i=1;i<=n;i++)cin>>arr[i];
vector<pair<int,int>> connection(n+1);
vector<int> left(n+1),right(n+1);
vector<long long> pref(n+2);
auto solve = [&](int l,int r){
pref[l-1]=0;
for(int i=l;i<=r;i++)pref[i]=pref[i-1]+arr[i];
stack<pair<int,int>> s;
s.emplace(INF,l-1);
for(int i=l;i<=r;i++){
while(s.top().first<=arr[i])s.pop();
connection[i]=s.top();
left[i]=s.top().second;
s.emplace(arr[i],i);
}
while(!s.empty())s.pop();
s.emplace(INF,r+1);
for(int i=r;i>=l;i--){
while(s.top().first<=arr[i])s.pop();
connection[i]=min(s.top(),connection[i]);
right[i]=s.top().second;
s.emplace(arr[i],i);
}
vector<vector<int>> adj(n+1);
for(int i=l;i<=r;i++){
adj[connection[i].second].emplace_back(i);
}
int ans = 0;
function<void(int,int)> dfs = [&](int x,int threshold){
if(pref[right[x]-1]-pref[left[x]]<threshold)return;
ans++;
for(int&i:adj[x])dfs(i,arr[x]);
};
for(int&i:adj[l-1])dfs(i,0);
return ans;
};
int q;
cin >> q;
for(int i=1;i<=q;i++){
int type;cin>>type;
if(type==1){
int x,y;cin>>x>>y;
arr[x]=y;
} else {
int l,r;cin>>l>>r;
cout << solve(l,r) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
9504 KB |
Output is correct |
3 |
Correct |
11 ms |
8284 KB |
Output is correct |
4 |
Correct |
16 ms |
9296 KB |
Output is correct |
5 |
Correct |
12 ms |
8540 KB |
Output is correct |
6 |
Correct |
17 ms |
8796 KB |
Output is correct |
7 |
Correct |
12 ms |
7516 KB |
Output is correct |
8 |
Correct |
16 ms |
8796 KB |
Output is correct |
9 |
Correct |
12 ms |
7352 KB |
Output is correct |
10 |
Correct |
12 ms |
8284 KB |
Output is correct |
11 |
Correct |
10 ms |
7184 KB |
Output is correct |
12 |
Correct |
11 ms |
8040 KB |
Output is correct |
13 |
Correct |
12 ms |
8028 KB |
Output is correct |
14 |
Correct |
13 ms |
8028 KB |
Output is correct |
15 |
Correct |
14 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
9504 KB |
Output is correct |
23 |
Correct |
11 ms |
8284 KB |
Output is correct |
24 |
Correct |
16 ms |
9296 KB |
Output is correct |
25 |
Correct |
12 ms |
8540 KB |
Output is correct |
26 |
Correct |
17 ms |
8796 KB |
Output is correct |
27 |
Correct |
12 ms |
7516 KB |
Output is correct |
28 |
Correct |
16 ms |
8796 KB |
Output is correct |
29 |
Correct |
12 ms |
7352 KB |
Output is correct |
30 |
Correct |
12 ms |
8284 KB |
Output is correct |
31 |
Correct |
10 ms |
7184 KB |
Output is correct |
32 |
Correct |
11 ms |
8040 KB |
Output is correct |
33 |
Correct |
12 ms |
8028 KB |
Output is correct |
34 |
Correct |
13 ms |
8028 KB |
Output is correct |
35 |
Correct |
14 ms |
8540 KB |
Output is correct |
36 |
Correct |
847 ms |
9484 KB |
Output is correct |
37 |
Correct |
1304 ms |
8096 KB |
Output is correct |
38 |
Correct |
1450 ms |
8352 KB |
Output is correct |
39 |
Correct |
342 ms |
9000 KB |
Output is correct |
40 |
Correct |
1505 ms |
8244 KB |
Output is correct |
41 |
Correct |
1743 ms |
8952 KB |
Output is correct |
42 |
Correct |
2286 ms |
8740 KB |
Output is correct |
43 |
Correct |
1463 ms |
7460 KB |
Output is correct |
44 |
Correct |
1733 ms |
7468 KB |
Output is correct |
45 |
Correct |
768 ms |
7968 KB |
Output is correct |
46 |
Correct |
1132 ms |
8160 KB |
Output is correct |
47 |
Correct |
1382 ms |
7268 KB |
Output is correct |
48 |
Correct |
589 ms |
7976 KB |
Output is correct |
49 |
Correct |
1977 ms |
7888 KB |
Output is correct |
50 |
Correct |
1036 ms |
8240 KB |
Output is correct |
51 |
Execution timed out |
4089 ms |
8484 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
9504 KB |
Output is correct |
3 |
Correct |
11 ms |
8284 KB |
Output is correct |
4 |
Correct |
16 ms |
9296 KB |
Output is correct |
5 |
Correct |
12 ms |
8540 KB |
Output is correct |
6 |
Correct |
17 ms |
8796 KB |
Output is correct |
7 |
Correct |
12 ms |
7516 KB |
Output is correct |
8 |
Correct |
16 ms |
8796 KB |
Output is correct |
9 |
Correct |
12 ms |
7352 KB |
Output is correct |
10 |
Correct |
12 ms |
8284 KB |
Output is correct |
11 |
Correct |
10 ms |
7184 KB |
Output is correct |
12 |
Correct |
11 ms |
8040 KB |
Output is correct |
13 |
Correct |
12 ms |
8028 KB |
Output is correct |
14 |
Correct |
13 ms |
8028 KB |
Output is correct |
15 |
Correct |
14 ms |
8540 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4086 ms |
8628 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 |
13 ms |
9504 KB |
Output is correct |
3 |
Correct |
11 ms |
8284 KB |
Output is correct |
4 |
Correct |
16 ms |
9296 KB |
Output is correct |
5 |
Correct |
12 ms |
8540 KB |
Output is correct |
6 |
Correct |
17 ms |
8796 KB |
Output is correct |
7 |
Correct |
12 ms |
7516 KB |
Output is correct |
8 |
Correct |
16 ms |
8796 KB |
Output is correct |
9 |
Correct |
12 ms |
7352 KB |
Output is correct |
10 |
Correct |
12 ms |
8284 KB |
Output is correct |
11 |
Correct |
10 ms |
7184 KB |
Output is correct |
12 |
Correct |
11 ms |
8040 KB |
Output is correct |
13 |
Correct |
12 ms |
8028 KB |
Output is correct |
14 |
Correct |
13 ms |
8028 KB |
Output is correct |
15 |
Correct |
14 ms |
8540 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4083 ms |
9708 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
9504 KB |
Output is correct |
23 |
Correct |
11 ms |
8284 KB |
Output is correct |
24 |
Correct |
16 ms |
9296 KB |
Output is correct |
25 |
Correct |
12 ms |
8540 KB |
Output is correct |
26 |
Correct |
17 ms |
8796 KB |
Output is correct |
27 |
Correct |
12 ms |
7516 KB |
Output is correct |
28 |
Correct |
16 ms |
8796 KB |
Output is correct |
29 |
Correct |
12 ms |
7352 KB |
Output is correct |
30 |
Correct |
12 ms |
8284 KB |
Output is correct |
31 |
Correct |
10 ms |
7184 KB |
Output is correct |
32 |
Correct |
11 ms |
8040 KB |
Output is correct |
33 |
Correct |
12 ms |
8028 KB |
Output is correct |
34 |
Correct |
13 ms |
8028 KB |
Output is correct |
35 |
Correct |
14 ms |
8540 KB |
Output is correct |
36 |
Correct |
847 ms |
9484 KB |
Output is correct |
37 |
Correct |
1304 ms |
8096 KB |
Output is correct |
38 |
Correct |
1450 ms |
8352 KB |
Output is correct |
39 |
Correct |
342 ms |
9000 KB |
Output is correct |
40 |
Correct |
1505 ms |
8244 KB |
Output is correct |
41 |
Correct |
1743 ms |
8952 KB |
Output is correct |
42 |
Correct |
2286 ms |
8740 KB |
Output is correct |
43 |
Correct |
1463 ms |
7460 KB |
Output is correct |
44 |
Correct |
1733 ms |
7468 KB |
Output is correct |
45 |
Correct |
768 ms |
7968 KB |
Output is correct |
46 |
Correct |
1132 ms |
8160 KB |
Output is correct |
47 |
Correct |
1382 ms |
7268 KB |
Output is correct |
48 |
Correct |
589 ms |
7976 KB |
Output is correct |
49 |
Correct |
1977 ms |
7888 KB |
Output is correct |
50 |
Correct |
1036 ms |
8240 KB |
Output is correct |
51 |
Execution timed out |
4089 ms |
8484 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |