#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, q, t, x, y, a[nx], l[nx], r[nx], sm[nx], rt, dp[nx], res;
void dfs(int u)
{
sm[u]=a[u];
if (l[u]) dfs(l[u]), sm[u]+=sm[l[u]];
if (r[u]) dfs(r[u]), sm[u]+=sm[r[u]];
}
void dfs2(int u)
{
if (l[u]&&sm[l[u]]>=a[u]) dp[l[u]]=1, dfs2(l[u]);
if (r[u]&&sm[r[u]]>=a[u]) dp[r[u]]=1, dfs2(r[u]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i];
cin>>q;
while (q--)
{
cin>>t>>x>>y;
if (t==1) a[x]=y;
else
{
for (int i=x; i<=y; i++) l[i]=r[i]=0;
stack<ll> s;
for (int i=x; i<=y; i++)
{
while (!s.empty()&&a[s.top()]<a[i]) l[i]=s.top(), s.pop();
if (s.empty()) rt=i;
else r[s.top()]=i;
s.push(i);
}
res=0;
dfs(rt);
for (int i=x; i<=y; i++) dp[i]=0;
dp[rt]=1;
dfs2(rt);
for (int i=x; i<=y; i++) res+=dp[i];
cout<<res<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
472 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
476 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
4188 KB |
Output is correct |
3 |
Correct |
6 ms |
4184 KB |
Output is correct |
4 |
Correct |
8 ms |
4348 KB |
Output is correct |
5 |
Correct |
7 ms |
4188 KB |
Output is correct |
6 |
Correct |
10 ms |
4188 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
10 ms |
4188 KB |
Output is correct |
9 |
Correct |
9 ms |
4188 KB |
Output is correct |
10 |
Correct |
7 ms |
4184 KB |
Output is correct |
11 |
Correct |
6 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4188 KB |
Output is correct |
13 |
Correct |
7 ms |
4188 KB |
Output is correct |
14 |
Correct |
8 ms |
4564 KB |
Output is correct |
15 |
Correct |
9 ms |
4336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
472 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
476 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
348 KB |
Output is correct |
22 |
Correct |
9 ms |
4188 KB |
Output is correct |
23 |
Correct |
6 ms |
4184 KB |
Output is correct |
24 |
Correct |
8 ms |
4348 KB |
Output is correct |
25 |
Correct |
7 ms |
4188 KB |
Output is correct |
26 |
Correct |
10 ms |
4188 KB |
Output is correct |
27 |
Correct |
7 ms |
4188 KB |
Output is correct |
28 |
Correct |
10 ms |
4188 KB |
Output is correct |
29 |
Correct |
9 ms |
4188 KB |
Output is correct |
30 |
Correct |
7 ms |
4184 KB |
Output is correct |
31 |
Correct |
6 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4188 KB |
Output is correct |
33 |
Correct |
7 ms |
4188 KB |
Output is correct |
34 |
Correct |
8 ms |
4564 KB |
Output is correct |
35 |
Correct |
9 ms |
4336 KB |
Output is correct |
36 |
Correct |
139 ms |
5204 KB |
Output is correct |
37 |
Correct |
237 ms |
4688 KB |
Output is correct |
38 |
Correct |
285 ms |
4532 KB |
Output is correct |
39 |
Correct |
59 ms |
4988 KB |
Output is correct |
40 |
Correct |
289 ms |
4692 KB |
Output is correct |
41 |
Correct |
563 ms |
5476 KB |
Output is correct |
42 |
Correct |
737 ms |
5204 KB |
Output is correct |
43 |
Correct |
380 ms |
4712 KB |
Output is correct |
44 |
Correct |
423 ms |
4692 KB |
Output is correct |
45 |
Correct |
168 ms |
4948 KB |
Output is correct |
46 |
Correct |
201 ms |
4832 KB |
Output is correct |
47 |
Correct |
298 ms |
4648 KB |
Output is correct |
48 |
Correct |
143 ms |
4556 KB |
Output is correct |
49 |
Correct |
463 ms |
4468 KB |
Output is correct |
50 |
Correct |
243 ms |
4952 KB |
Output is correct |
51 |
Correct |
1126 ms |
4956 KB |
Output is correct |
52 |
Correct |
1270 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
4188 KB |
Output is correct |
3 |
Correct |
6 ms |
4184 KB |
Output is correct |
4 |
Correct |
8 ms |
4348 KB |
Output is correct |
5 |
Correct |
7 ms |
4188 KB |
Output is correct |
6 |
Correct |
10 ms |
4188 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
10 ms |
4188 KB |
Output is correct |
9 |
Correct |
9 ms |
4188 KB |
Output is correct |
10 |
Correct |
7 ms |
4184 KB |
Output is correct |
11 |
Correct |
6 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4188 KB |
Output is correct |
13 |
Correct |
7 ms |
4188 KB |
Output is correct |
14 |
Correct |
8 ms |
4564 KB |
Output is correct |
15 |
Correct |
9 ms |
4336 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4083 ms |
5068 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
4188 KB |
Output is correct |
3 |
Correct |
6 ms |
4184 KB |
Output is correct |
4 |
Correct |
8 ms |
4348 KB |
Output is correct |
5 |
Correct |
7 ms |
4188 KB |
Output is correct |
6 |
Correct |
10 ms |
4188 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
10 ms |
4188 KB |
Output is correct |
9 |
Correct |
9 ms |
4188 KB |
Output is correct |
10 |
Correct |
7 ms |
4184 KB |
Output is correct |
11 |
Correct |
6 ms |
4180 KB |
Output is correct |
12 |
Correct |
7 ms |
4188 KB |
Output is correct |
13 |
Correct |
7 ms |
4188 KB |
Output is correct |
14 |
Correct |
8 ms |
4564 KB |
Output is correct |
15 |
Correct |
9 ms |
4336 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4086 ms |
5500 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
472 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
476 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
348 KB |
Output is correct |
22 |
Correct |
9 ms |
4188 KB |
Output is correct |
23 |
Correct |
6 ms |
4184 KB |
Output is correct |
24 |
Correct |
8 ms |
4348 KB |
Output is correct |
25 |
Correct |
7 ms |
4188 KB |
Output is correct |
26 |
Correct |
10 ms |
4188 KB |
Output is correct |
27 |
Correct |
7 ms |
4188 KB |
Output is correct |
28 |
Correct |
10 ms |
4188 KB |
Output is correct |
29 |
Correct |
9 ms |
4188 KB |
Output is correct |
30 |
Correct |
7 ms |
4184 KB |
Output is correct |
31 |
Correct |
6 ms |
4180 KB |
Output is correct |
32 |
Correct |
7 ms |
4188 KB |
Output is correct |
33 |
Correct |
7 ms |
4188 KB |
Output is correct |
34 |
Correct |
8 ms |
4564 KB |
Output is correct |
35 |
Correct |
9 ms |
4336 KB |
Output is correct |
36 |
Correct |
139 ms |
5204 KB |
Output is correct |
37 |
Correct |
237 ms |
4688 KB |
Output is correct |
38 |
Correct |
285 ms |
4532 KB |
Output is correct |
39 |
Correct |
59 ms |
4988 KB |
Output is correct |
40 |
Correct |
289 ms |
4692 KB |
Output is correct |
41 |
Correct |
563 ms |
5476 KB |
Output is correct |
42 |
Correct |
737 ms |
5204 KB |
Output is correct |
43 |
Correct |
380 ms |
4712 KB |
Output is correct |
44 |
Correct |
423 ms |
4692 KB |
Output is correct |
45 |
Correct |
168 ms |
4948 KB |
Output is correct |
46 |
Correct |
201 ms |
4832 KB |
Output is correct |
47 |
Correct |
298 ms |
4648 KB |
Output is correct |
48 |
Correct |
143 ms |
4556 KB |
Output is correct |
49 |
Correct |
463 ms |
4468 KB |
Output is correct |
50 |
Correct |
243 ms |
4952 KB |
Output is correct |
51 |
Correct |
1126 ms |
4956 KB |
Output is correct |
52 |
Correct |
1270 ms |
4956 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Execution timed out |
4083 ms |
5068 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |