#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int v[MAX_N + 1], leftt[MAX_N + 1], rightt[MAX_N + 1];
long long s[MAX_N + 1];
void init( int n ) {
for ( int i = 1; i <= n; i++ )
s[i] = s[i - 1] + v[i];
for ( int i = 1; i < n; i++ ) {
int l = 0, r = i + 1;
while ( r - l > 1 ) {
int mid = (l + r) / 2;
if ( s[i] - s[mid - 1] >= v[i + 1] )
l = mid;
else
r = mid;
}
leftt[i] = l;
}
for ( int i = 2; i <= n; i++ ) {
int l = i - 1, r = n + 1;
while ( r - l > 1 ) {
int mid = (l + r) / 2;
if ( s[mid] - s[i - 1] >= v[i - 1] )
r = mid;
else
l = mid;
}
rightt[i] = r;
}
}
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ )
cin >> v[i];
init( n );
int q;
cin >> q;
while ( q-- ) {
int t, l, r;
cin >> t >> l >> r;
if ( t == 1 ) {
v[l] = r;
init( n );
continue;
}
int ans = 0;
for ( int i = l; i <= r; i++ ) {
int p;
p = i;
while ( p >= l + 1 && (rightt[p] <= i || (rightt[p] <= r && leftt[rightt[p] - 1] >= p)) )
p--;
if ( p != l )
continue;
p = i;
while ( p <= r - 1 && (leftt[p] >= i || (leftt[p] >= l && rightt[leftt[p] + 1] <= p)) )
p++;
if ( p == r )
ans++;
}
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
13 ms |
360 KB |
Output is correct |
6 |
Correct |
5 ms |
360 KB |
Output is correct |
7 |
Correct |
12 ms |
360 KB |
Output is correct |
8 |
Correct |
7 ms |
360 KB |
Output is correct |
9 |
Correct |
9 ms |
612 KB |
Output is correct |
10 |
Correct |
19 ms |
360 KB |
Output is correct |
11 |
Correct |
12 ms |
360 KB |
Output is correct |
12 |
Correct |
16 ms |
360 KB |
Output is correct |
13 |
Correct |
5 ms |
360 KB |
Output is correct |
14 |
Correct |
12 ms |
356 KB |
Output is correct |
15 |
Correct |
10 ms |
612 KB |
Output is correct |
16 |
Correct |
8 ms |
360 KB |
Output is correct |
17 |
Correct |
11 ms |
360 KB |
Output is correct |
18 |
Correct |
4 ms |
360 KB |
Output is correct |
19 |
Correct |
12 ms |
360 KB |
Output is correct |
20 |
Correct |
30 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
851 ms |
2948 KB |
Output is correct |
3 |
Correct |
124 ms |
2640 KB |
Output is correct |
4 |
Correct |
1876 ms |
2952 KB |
Output is correct |
5 |
Correct |
246 ms |
2712 KB |
Output is correct |
6 |
Execution timed out |
4006 ms |
3084 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
13 ms |
360 KB |
Output is correct |
6 |
Correct |
5 ms |
360 KB |
Output is correct |
7 |
Correct |
12 ms |
360 KB |
Output is correct |
8 |
Correct |
7 ms |
360 KB |
Output is correct |
9 |
Correct |
9 ms |
612 KB |
Output is correct |
10 |
Correct |
19 ms |
360 KB |
Output is correct |
11 |
Correct |
12 ms |
360 KB |
Output is correct |
12 |
Correct |
16 ms |
360 KB |
Output is correct |
13 |
Correct |
5 ms |
360 KB |
Output is correct |
14 |
Correct |
12 ms |
356 KB |
Output is correct |
15 |
Correct |
10 ms |
612 KB |
Output is correct |
16 |
Correct |
8 ms |
360 KB |
Output is correct |
17 |
Correct |
11 ms |
360 KB |
Output is correct |
18 |
Correct |
4 ms |
360 KB |
Output is correct |
19 |
Correct |
12 ms |
360 KB |
Output is correct |
20 |
Correct |
30 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
851 ms |
2948 KB |
Output is correct |
23 |
Correct |
124 ms |
2640 KB |
Output is correct |
24 |
Correct |
1876 ms |
2952 KB |
Output is correct |
25 |
Correct |
246 ms |
2712 KB |
Output is correct |
26 |
Execution timed out |
4006 ms |
3084 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
851 ms |
2948 KB |
Output is correct |
3 |
Correct |
124 ms |
2640 KB |
Output is correct |
4 |
Correct |
1876 ms |
2952 KB |
Output is correct |
5 |
Correct |
246 ms |
2712 KB |
Output is correct |
6 |
Execution timed out |
4006 ms |
3084 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
851 ms |
2948 KB |
Output is correct |
3 |
Correct |
124 ms |
2640 KB |
Output is correct |
4 |
Correct |
1876 ms |
2952 KB |
Output is correct |
5 |
Correct |
246 ms |
2712 KB |
Output is correct |
6 |
Execution timed out |
4006 ms |
3084 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
13 ms |
360 KB |
Output is correct |
6 |
Correct |
5 ms |
360 KB |
Output is correct |
7 |
Correct |
12 ms |
360 KB |
Output is correct |
8 |
Correct |
7 ms |
360 KB |
Output is correct |
9 |
Correct |
9 ms |
612 KB |
Output is correct |
10 |
Correct |
19 ms |
360 KB |
Output is correct |
11 |
Correct |
12 ms |
360 KB |
Output is correct |
12 |
Correct |
16 ms |
360 KB |
Output is correct |
13 |
Correct |
5 ms |
360 KB |
Output is correct |
14 |
Correct |
12 ms |
356 KB |
Output is correct |
15 |
Correct |
10 ms |
612 KB |
Output is correct |
16 |
Correct |
8 ms |
360 KB |
Output is correct |
17 |
Correct |
11 ms |
360 KB |
Output is correct |
18 |
Correct |
4 ms |
360 KB |
Output is correct |
19 |
Correct |
12 ms |
360 KB |
Output is correct |
20 |
Correct |
30 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
851 ms |
2948 KB |
Output is correct |
23 |
Correct |
124 ms |
2640 KB |
Output is correct |
24 |
Correct |
1876 ms |
2952 KB |
Output is correct |
25 |
Correct |
246 ms |
2712 KB |
Output is correct |
26 |
Execution timed out |
4006 ms |
3084 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |