#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,v[100005],q,s[100005],mars[100005];
int solve(int l,int r)
{
s[l-1]=0;
mars[l-1]=0;
for(int i=l;i<=r;i++)
{
s[i]=s[i-1]+v[i];
mars[i]=0;
}
stack<int> coada;
for(int i=l;i<=r;i++)
{
while(!coada.empty()&&v[coada.top()]<v[i])
coada.pop();
int st=l-1;
if(!coada.empty())
st=coada.top();
if(s[i-1]-s[st]<v[i])
{
mars[st+1]++;
mars[i]--;
}
coada.push(i);
}
while(!coada.empty())
coada.pop();
for(int i=r;i>=l;i--)
{
while(!coada.empty()&&v[coada.top()]<v[i])
coada.pop();
int dr=r+1;
if(!coada.empty())
dr=coada.top();
if(s[dr-1]-s[i]<v[i])
{
mars[i+1]++;
mars[dr]--;
}
coada.push(i);
}
int ans=0;
for(int i=l;i<=r;i++)
{
mars[i]+=mars[i-1];
if(mars[i]==0)
ans++;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
cin>>q;
if(q<=1000)
{
while(q--)
{
int tip;
cin>>tip;
if(tip==1)
{
int poz,val;
cin>>poz>>val;
v[poz]=val;
}
else
{
int l,r;
cin>>l>>r;
cout<<solve(l,r)<<'\n';
}
}
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2524 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
2 ms |
2536 KB |
Output is correct |
20 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
8 ms |
3164 KB |
Output is correct |
3 |
Correct |
9 ms |
3100 KB |
Output is correct |
4 |
Correct |
9 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
2908 KB |
Output is correct |
6 |
Correct |
11 ms |
3552 KB |
Output is correct |
7 |
Correct |
7 ms |
2888 KB |
Output is correct |
8 |
Correct |
13 ms |
3676 KB |
Output is correct |
9 |
Correct |
7 ms |
2876 KB |
Output is correct |
10 |
Correct |
9 ms |
3160 KB |
Output is correct |
11 |
Correct |
7 ms |
2908 KB |
Output is correct |
12 |
Correct |
8 ms |
2908 KB |
Output is correct |
13 |
Correct |
10 ms |
2908 KB |
Output is correct |
14 |
Correct |
10 ms |
3416 KB |
Output is correct |
15 |
Correct |
10 ms |
3656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2524 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
2 ms |
2536 KB |
Output is correct |
20 |
Correct |
4 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
8 ms |
3164 KB |
Output is correct |
23 |
Correct |
9 ms |
3100 KB |
Output is correct |
24 |
Correct |
9 ms |
3164 KB |
Output is correct |
25 |
Correct |
8 ms |
2908 KB |
Output is correct |
26 |
Correct |
11 ms |
3552 KB |
Output is correct |
27 |
Correct |
7 ms |
2888 KB |
Output is correct |
28 |
Correct |
13 ms |
3676 KB |
Output is correct |
29 |
Correct |
7 ms |
2876 KB |
Output is correct |
30 |
Correct |
9 ms |
3160 KB |
Output is correct |
31 |
Correct |
7 ms |
2908 KB |
Output is correct |
32 |
Correct |
8 ms |
2908 KB |
Output is correct |
33 |
Correct |
10 ms |
2908 KB |
Output is correct |
34 |
Correct |
10 ms |
3416 KB |
Output is correct |
35 |
Correct |
10 ms |
3656 KB |
Output is correct |
36 |
Correct |
218 ms |
3396 KB |
Output is correct |
37 |
Correct |
364 ms |
2904 KB |
Output is correct |
38 |
Correct |
426 ms |
3416 KB |
Output is correct |
39 |
Correct |
90 ms |
3160 KB |
Output is correct |
40 |
Correct |
481 ms |
2908 KB |
Output is correct |
41 |
Correct |
648 ms |
3772 KB |
Output is correct |
42 |
Correct |
814 ms |
3768 KB |
Output is correct |
43 |
Correct |
646 ms |
3004 KB |
Output is correct |
44 |
Correct |
806 ms |
3160 KB |
Output is correct |
45 |
Correct |
239 ms |
3372 KB |
Output is correct |
46 |
Correct |
349 ms |
3164 KB |
Output is correct |
47 |
Correct |
507 ms |
3156 KB |
Output is correct |
48 |
Correct |
244 ms |
3048 KB |
Output is correct |
49 |
Correct |
844 ms |
3056 KB |
Output is correct |
50 |
Correct |
363 ms |
3660 KB |
Output is correct |
51 |
Correct |
1736 ms |
3672 KB |
Output is correct |
52 |
Correct |
1752 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
8 ms |
3164 KB |
Output is correct |
3 |
Correct |
9 ms |
3100 KB |
Output is correct |
4 |
Correct |
9 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
2908 KB |
Output is correct |
6 |
Correct |
11 ms |
3552 KB |
Output is correct |
7 |
Correct |
7 ms |
2888 KB |
Output is correct |
8 |
Correct |
13 ms |
3676 KB |
Output is correct |
9 |
Correct |
7 ms |
2876 KB |
Output is correct |
10 |
Correct |
9 ms |
3160 KB |
Output is correct |
11 |
Correct |
7 ms |
2908 KB |
Output is correct |
12 |
Correct |
8 ms |
2908 KB |
Output is correct |
13 |
Correct |
10 ms |
2908 KB |
Output is correct |
14 |
Correct |
10 ms |
3416 KB |
Output is correct |
15 |
Correct |
10 ms |
3656 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Incorrect |
5 ms |
3160 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
8 ms |
3164 KB |
Output is correct |
3 |
Correct |
9 ms |
3100 KB |
Output is correct |
4 |
Correct |
9 ms |
3164 KB |
Output is correct |
5 |
Correct |
8 ms |
2908 KB |
Output is correct |
6 |
Correct |
11 ms |
3552 KB |
Output is correct |
7 |
Correct |
7 ms |
2888 KB |
Output is correct |
8 |
Correct |
13 ms |
3676 KB |
Output is correct |
9 |
Correct |
7 ms |
2876 KB |
Output is correct |
10 |
Correct |
9 ms |
3160 KB |
Output is correct |
11 |
Correct |
7 ms |
2908 KB |
Output is correct |
12 |
Correct |
8 ms |
2908 KB |
Output is correct |
13 |
Correct |
10 ms |
2908 KB |
Output is correct |
14 |
Correct |
10 ms |
3416 KB |
Output is correct |
15 |
Correct |
10 ms |
3656 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Incorrect |
7 ms |
3136 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2524 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
3 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
2 ms |
2536 KB |
Output is correct |
20 |
Correct |
4 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
8 ms |
3164 KB |
Output is correct |
23 |
Correct |
9 ms |
3100 KB |
Output is correct |
24 |
Correct |
9 ms |
3164 KB |
Output is correct |
25 |
Correct |
8 ms |
2908 KB |
Output is correct |
26 |
Correct |
11 ms |
3552 KB |
Output is correct |
27 |
Correct |
7 ms |
2888 KB |
Output is correct |
28 |
Correct |
13 ms |
3676 KB |
Output is correct |
29 |
Correct |
7 ms |
2876 KB |
Output is correct |
30 |
Correct |
9 ms |
3160 KB |
Output is correct |
31 |
Correct |
7 ms |
2908 KB |
Output is correct |
32 |
Correct |
8 ms |
2908 KB |
Output is correct |
33 |
Correct |
10 ms |
2908 KB |
Output is correct |
34 |
Correct |
10 ms |
3416 KB |
Output is correct |
35 |
Correct |
10 ms |
3656 KB |
Output is correct |
36 |
Correct |
218 ms |
3396 KB |
Output is correct |
37 |
Correct |
364 ms |
2904 KB |
Output is correct |
38 |
Correct |
426 ms |
3416 KB |
Output is correct |
39 |
Correct |
90 ms |
3160 KB |
Output is correct |
40 |
Correct |
481 ms |
2908 KB |
Output is correct |
41 |
Correct |
648 ms |
3772 KB |
Output is correct |
42 |
Correct |
814 ms |
3768 KB |
Output is correct |
43 |
Correct |
646 ms |
3004 KB |
Output is correct |
44 |
Correct |
806 ms |
3160 KB |
Output is correct |
45 |
Correct |
239 ms |
3372 KB |
Output is correct |
46 |
Correct |
349 ms |
3164 KB |
Output is correct |
47 |
Correct |
507 ms |
3156 KB |
Output is correct |
48 |
Correct |
244 ms |
3048 KB |
Output is correct |
49 |
Correct |
844 ms |
3056 KB |
Output is correct |
50 |
Correct |
363 ms |
3660 KB |
Output is correct |
51 |
Correct |
1736 ms |
3672 KB |
Output is correct |
52 |
Correct |
1752 ms |
3420 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Incorrect |
5 ms |
3160 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |