#include <bits/stdc++.h>
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n,q;
std::cin>>n;
std::vector<int> vec;
for(int i=0;i<n;i++){
int x;
std::cin>>x;
vec.push_back(x);
}
std::cin>>q;
for(;q--;){
int a;
std::cin>>a;
if(a==1){
int b,c;
std::cin>>b>>c;
b--;
vec[b]=c;
}else{
int b,c;
std::cin>>b>>c;
b--;
std::vector<long long> sums;
std::vector<std::pair<long long,std::pair<long long,int>>> stk;//size of fish to the right, sum, number which can win
for(int i=b;i<c;i++){
stk.push_back({0,{0,0}});//for merging
while(stk.size()>=2&&stk[stk.size()-2].first<vec[i]){
//std::cout<<"m!\n";
if(stk.back().second.first>=stk[stk.size()-2].first){
stk[stk.size()-2].second.second+=stk.back().second.second;
}
stk[stk.size()-2].second.first+=stk.back().second.first;//add sum
stk.pop_back();
}
stk.back().first=vec[i];
stk.back().second.second=stk.back().second.first>=vec[i]?stk.back().second.second+1:1;
stk.back().second.first+=vec[i];
}
while(stk.size()>=2){
//std::cout<<"m\m";
if(stk.back().second.first>=stk[stk.size()-2].first){
stk[stk.size()-2].second.second+=stk.back().second.second;
}
stk[stk.size()-2].second.first+=stk.back().second.first;//add sum
stk.pop_back();
}
std::cout<<stk.back().second.second<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
420 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
612 KB |
Output is correct |
11 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1504 KB |
Output is correct |
3 |
Correct |
6 ms |
1264 KB |
Output is correct |
4 |
Correct |
7 ms |
1680 KB |
Output is correct |
5 |
Correct |
9 ms |
1248 KB |
Output is correct |
6 |
Correct |
9 ms |
1756 KB |
Output is correct |
7 |
Correct |
6 ms |
1328 KB |
Output is correct |
8 |
Correct |
8 ms |
1760 KB |
Output is correct |
9 |
Correct |
6 ms |
1244 KB |
Output is correct |
10 |
Correct |
7 ms |
1504 KB |
Output is correct |
11 |
Correct |
5 ms |
1344 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
6 ms |
1272 KB |
Output is correct |
14 |
Correct |
7 ms |
1680 KB |
Output is correct |
15 |
Correct |
9 ms |
1756 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
420 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
612 KB |
Output is correct |
11 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
1504 KB |
Output is correct |
23 |
Correct |
6 ms |
1264 KB |
Output is correct |
24 |
Correct |
7 ms |
1680 KB |
Output is correct |
25 |
Correct |
9 ms |
1248 KB |
Output is correct |
26 |
Correct |
9 ms |
1756 KB |
Output is correct |
27 |
Correct |
6 ms |
1328 KB |
Output is correct |
28 |
Correct |
8 ms |
1760 KB |
Output is correct |
29 |
Correct |
6 ms |
1244 KB |
Output is correct |
30 |
Correct |
7 ms |
1504 KB |
Output is correct |
31 |
Correct |
5 ms |
1344 KB |
Output is correct |
32 |
Correct |
6 ms |
1248 KB |
Output is correct |
33 |
Correct |
6 ms |
1272 KB |
Output is correct |
34 |
Correct |
7 ms |
1680 KB |
Output is correct |
35 |
Correct |
9 ms |
1756 KB |
Output is correct |
36 |
Correct |
174 ms |
1504 KB |
Output is correct |
37 |
Correct |
264 ms |
1244 KB |
Output is correct |
38 |
Correct |
298 ms |
1492 KB |
Output is correct |
39 |
Correct |
72 ms |
1504 KB |
Output is correct |
40 |
Correct |
328 ms |
1256 KB |
Output is correct |
41 |
Correct |
291 ms |
1960 KB |
Output is correct |
42 |
Correct |
355 ms |
1760 KB |
Output is correct |
43 |
Correct |
300 ms |
1244 KB |
Output is correct |
44 |
Correct |
349 ms |
1248 KB |
Output is correct |
45 |
Correct |
181 ms |
1504 KB |
Output is correct |
46 |
Correct |
250 ms |
1556 KB |
Output is correct |
47 |
Correct |
382 ms |
1248 KB |
Output is correct |
48 |
Correct |
112 ms |
1244 KB |
Output is correct |
49 |
Correct |
381 ms |
1248 KB |
Output is correct |
50 |
Correct |
219 ms |
1756 KB |
Output is correct |
51 |
Correct |
772 ms |
1764 KB |
Output is correct |
52 |
Correct |
950 ms |
2004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1504 KB |
Output is correct |
3 |
Correct |
6 ms |
1264 KB |
Output is correct |
4 |
Correct |
7 ms |
1680 KB |
Output is correct |
5 |
Correct |
9 ms |
1248 KB |
Output is correct |
6 |
Correct |
9 ms |
1756 KB |
Output is correct |
7 |
Correct |
6 ms |
1328 KB |
Output is correct |
8 |
Correct |
8 ms |
1760 KB |
Output is correct |
9 |
Correct |
6 ms |
1244 KB |
Output is correct |
10 |
Correct |
7 ms |
1504 KB |
Output is correct |
11 |
Correct |
5 ms |
1344 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
6 ms |
1272 KB |
Output is correct |
14 |
Correct |
7 ms |
1680 KB |
Output is correct |
15 |
Correct |
9 ms |
1756 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4045 ms |
1492 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1504 KB |
Output is correct |
3 |
Correct |
6 ms |
1264 KB |
Output is correct |
4 |
Correct |
7 ms |
1680 KB |
Output is correct |
5 |
Correct |
9 ms |
1248 KB |
Output is correct |
6 |
Correct |
9 ms |
1756 KB |
Output is correct |
7 |
Correct |
6 ms |
1328 KB |
Output is correct |
8 |
Correct |
8 ms |
1760 KB |
Output is correct |
9 |
Correct |
6 ms |
1244 KB |
Output is correct |
10 |
Correct |
7 ms |
1504 KB |
Output is correct |
11 |
Correct |
5 ms |
1344 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
6 ms |
1272 KB |
Output is correct |
14 |
Correct |
7 ms |
1680 KB |
Output is correct |
15 |
Correct |
9 ms |
1756 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4086 ms |
2116 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
420 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
612 KB |
Output is correct |
11 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
1504 KB |
Output is correct |
23 |
Correct |
6 ms |
1264 KB |
Output is correct |
24 |
Correct |
7 ms |
1680 KB |
Output is correct |
25 |
Correct |
9 ms |
1248 KB |
Output is correct |
26 |
Correct |
9 ms |
1756 KB |
Output is correct |
27 |
Correct |
6 ms |
1328 KB |
Output is correct |
28 |
Correct |
8 ms |
1760 KB |
Output is correct |
29 |
Correct |
6 ms |
1244 KB |
Output is correct |
30 |
Correct |
7 ms |
1504 KB |
Output is correct |
31 |
Correct |
5 ms |
1344 KB |
Output is correct |
32 |
Correct |
6 ms |
1248 KB |
Output is correct |
33 |
Correct |
6 ms |
1272 KB |
Output is correct |
34 |
Correct |
7 ms |
1680 KB |
Output is correct |
35 |
Correct |
9 ms |
1756 KB |
Output is correct |
36 |
Correct |
174 ms |
1504 KB |
Output is correct |
37 |
Correct |
264 ms |
1244 KB |
Output is correct |
38 |
Correct |
298 ms |
1492 KB |
Output is correct |
39 |
Correct |
72 ms |
1504 KB |
Output is correct |
40 |
Correct |
328 ms |
1256 KB |
Output is correct |
41 |
Correct |
291 ms |
1960 KB |
Output is correct |
42 |
Correct |
355 ms |
1760 KB |
Output is correct |
43 |
Correct |
300 ms |
1244 KB |
Output is correct |
44 |
Correct |
349 ms |
1248 KB |
Output is correct |
45 |
Correct |
181 ms |
1504 KB |
Output is correct |
46 |
Correct |
250 ms |
1556 KB |
Output is correct |
47 |
Correct |
382 ms |
1248 KB |
Output is correct |
48 |
Correct |
112 ms |
1244 KB |
Output is correct |
49 |
Correct |
381 ms |
1248 KB |
Output is correct |
50 |
Correct |
219 ms |
1756 KB |
Output is correct |
51 |
Correct |
772 ms |
1764 KB |
Output is correct |
52 |
Correct |
950 ms |
2004 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Execution timed out |
4045 ms |
1492 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |