#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1987654321)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int n, q;
int arr[100005];
ll sum[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i) cin >> arr[i];
for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
cin >> q;
while(q--) {
int t, a, b;
cin >> t >> a >> b;
if(t == 1) {
arr[a] = b;
for(int i = a; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
}
else {
int mx[100005];
stack<int> st;
for(int i = a; i <= b; ++i) mx[i] = i - 1;
for(int i = a; i <= b; ++i) {
while(!st.empty() && arr[st.top()] <= arr[i]) {
if(st.top() + 1 < i && sum[i - 1] - sum[st.top()] < arr[st.top()]) mx[st.top() + 1] = i - 1;
st.pop();
}
st.push(i);
}
while(!st.empty()) {
if(st.top() + 1 < b + 1 && sum[b] - sum[st.top()] < arr[st.top()]) mx[st.top() + 1] = b;
st.pop();
}
for(int i = b; i >= a; --i) {
while(!st.empty() && arr[st.top()] <= arr[i]) {
if(i + 1 < st.top() && sum[st.top() - 1] - sum[i] < arr[st.top()]) mx[i + 1] = max(mx[i + 1], st.top() - 1);
st.pop();
}
st.push(i);
}
while(!st.empty()) {
if(a < st.top() && sum[st.top() - 1] - sum[a - 1] < arr[st.top()]) mx[a] = max(mx[a], st.top() - 1);
st.pop();
}
int ans = 0, i = a;
while(i <= b) {
ans += mx[i] - i + 1;
i = max(i + 1, mx[i] + 1);
}
cout << b - a + 1 - ans << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
9 ms |
1884 KB |
Output is correct |
3 |
Correct |
7 ms |
2132 KB |
Output is correct |
4 |
Correct |
8 ms |
2420 KB |
Output is correct |
5 |
Correct |
10 ms |
2224 KB |
Output is correct |
6 |
Correct |
14 ms |
2768 KB |
Output is correct |
7 |
Correct |
7 ms |
2092 KB |
Output is correct |
8 |
Correct |
12 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
2004 KB |
Output is correct |
10 |
Correct |
8 ms |
2452 KB |
Output is correct |
11 |
Correct |
7 ms |
2132 KB |
Output is correct |
12 |
Correct |
8 ms |
2032 KB |
Output is correct |
13 |
Correct |
8 ms |
2132 KB |
Output is correct |
14 |
Correct |
9 ms |
2368 KB |
Output is correct |
15 |
Correct |
12 ms |
2484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
0 ms |
596 KB |
Output is correct |
22 |
Correct |
9 ms |
1884 KB |
Output is correct |
23 |
Correct |
7 ms |
2132 KB |
Output is correct |
24 |
Correct |
8 ms |
2420 KB |
Output is correct |
25 |
Correct |
10 ms |
2224 KB |
Output is correct |
26 |
Correct |
14 ms |
2768 KB |
Output is correct |
27 |
Correct |
7 ms |
2092 KB |
Output is correct |
28 |
Correct |
12 ms |
2808 KB |
Output is correct |
29 |
Correct |
7 ms |
2004 KB |
Output is correct |
30 |
Correct |
8 ms |
2452 KB |
Output is correct |
31 |
Correct |
7 ms |
2132 KB |
Output is correct |
32 |
Correct |
8 ms |
2032 KB |
Output is correct |
33 |
Correct |
8 ms |
2132 KB |
Output is correct |
34 |
Correct |
9 ms |
2368 KB |
Output is correct |
35 |
Correct |
12 ms |
2484 KB |
Output is correct |
36 |
Correct |
243 ms |
2456 KB |
Output is correct |
37 |
Correct |
330 ms |
2208 KB |
Output is correct |
38 |
Correct |
329 ms |
2212 KB |
Output is correct |
39 |
Correct |
178 ms |
2460 KB |
Output is correct |
40 |
Correct |
363 ms |
2216 KB |
Output is correct |
41 |
Correct |
671 ms |
2860 KB |
Output is correct |
42 |
Correct |
828 ms |
2848 KB |
Output is correct |
43 |
Correct |
549 ms |
2084 KB |
Output is correct |
44 |
Correct |
616 ms |
2084 KB |
Output is correct |
45 |
Correct |
236 ms |
2448 KB |
Output is correct |
46 |
Correct |
348 ms |
2448 KB |
Output is correct |
47 |
Correct |
373 ms |
2160 KB |
Output is correct |
48 |
Correct |
304 ms |
2136 KB |
Output is correct |
49 |
Correct |
751 ms |
2132 KB |
Output is correct |
50 |
Correct |
400 ms |
2484 KB |
Output is correct |
51 |
Correct |
1656 ms |
2600 KB |
Output is correct |
52 |
Correct |
1586 ms |
2476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
9 ms |
1884 KB |
Output is correct |
3 |
Correct |
7 ms |
2132 KB |
Output is correct |
4 |
Correct |
8 ms |
2420 KB |
Output is correct |
5 |
Correct |
10 ms |
2224 KB |
Output is correct |
6 |
Correct |
14 ms |
2768 KB |
Output is correct |
7 |
Correct |
7 ms |
2092 KB |
Output is correct |
8 |
Correct |
12 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
2004 KB |
Output is correct |
10 |
Correct |
8 ms |
2452 KB |
Output is correct |
11 |
Correct |
7 ms |
2132 KB |
Output is correct |
12 |
Correct |
8 ms |
2032 KB |
Output is correct |
13 |
Correct |
8 ms |
2132 KB |
Output is correct |
14 |
Correct |
9 ms |
2368 KB |
Output is correct |
15 |
Correct |
12 ms |
2484 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Execution timed out |
4075 ms |
2508 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
9 ms |
1884 KB |
Output is correct |
3 |
Correct |
7 ms |
2132 KB |
Output is correct |
4 |
Correct |
8 ms |
2420 KB |
Output is correct |
5 |
Correct |
10 ms |
2224 KB |
Output is correct |
6 |
Correct |
14 ms |
2768 KB |
Output is correct |
7 |
Correct |
7 ms |
2092 KB |
Output is correct |
8 |
Correct |
12 ms |
2808 KB |
Output is correct |
9 |
Correct |
7 ms |
2004 KB |
Output is correct |
10 |
Correct |
8 ms |
2452 KB |
Output is correct |
11 |
Correct |
7 ms |
2132 KB |
Output is correct |
12 |
Correct |
8 ms |
2032 KB |
Output is correct |
13 |
Correct |
8 ms |
2132 KB |
Output is correct |
14 |
Correct |
9 ms |
2368 KB |
Output is correct |
15 |
Correct |
12 ms |
2484 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Execution timed out |
4064 ms |
2748 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
0 ms |
596 KB |
Output is correct |
22 |
Correct |
9 ms |
1884 KB |
Output is correct |
23 |
Correct |
7 ms |
2132 KB |
Output is correct |
24 |
Correct |
8 ms |
2420 KB |
Output is correct |
25 |
Correct |
10 ms |
2224 KB |
Output is correct |
26 |
Correct |
14 ms |
2768 KB |
Output is correct |
27 |
Correct |
7 ms |
2092 KB |
Output is correct |
28 |
Correct |
12 ms |
2808 KB |
Output is correct |
29 |
Correct |
7 ms |
2004 KB |
Output is correct |
30 |
Correct |
8 ms |
2452 KB |
Output is correct |
31 |
Correct |
7 ms |
2132 KB |
Output is correct |
32 |
Correct |
8 ms |
2032 KB |
Output is correct |
33 |
Correct |
8 ms |
2132 KB |
Output is correct |
34 |
Correct |
9 ms |
2368 KB |
Output is correct |
35 |
Correct |
12 ms |
2484 KB |
Output is correct |
36 |
Correct |
243 ms |
2456 KB |
Output is correct |
37 |
Correct |
330 ms |
2208 KB |
Output is correct |
38 |
Correct |
329 ms |
2212 KB |
Output is correct |
39 |
Correct |
178 ms |
2460 KB |
Output is correct |
40 |
Correct |
363 ms |
2216 KB |
Output is correct |
41 |
Correct |
671 ms |
2860 KB |
Output is correct |
42 |
Correct |
828 ms |
2848 KB |
Output is correct |
43 |
Correct |
549 ms |
2084 KB |
Output is correct |
44 |
Correct |
616 ms |
2084 KB |
Output is correct |
45 |
Correct |
236 ms |
2448 KB |
Output is correct |
46 |
Correct |
348 ms |
2448 KB |
Output is correct |
47 |
Correct |
373 ms |
2160 KB |
Output is correct |
48 |
Correct |
304 ms |
2136 KB |
Output is correct |
49 |
Correct |
751 ms |
2132 KB |
Output is correct |
50 |
Correct |
400 ms |
2484 KB |
Output is correct |
51 |
Correct |
1656 ms |
2600 KB |
Output is correct |
52 |
Correct |
1586 ms |
2476 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Execution timed out |
4075 ms |
2508 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |