#include <bits/stdc++.h>
using namespace std;
#define int long long
void answer(vector<int> arr){
int n = arr.size();
arr.insert(arr.begin(),0);
vector<int> S(n+1);
for(int i=1;i<=n;i++)S[i]=S[i-1]+arr[i];
vector<pair<int,int>> buffer(n+1);
for(int i=1;i<=n;i++)buffer[i]={arr[i]+S[i],i};
sort(buffer.begin(),buffer.end());
auto iter = buffer.begin();
set<int> possible;
vector<int> DP(n+1);
for(int i=1;i<=n;i++){
while(iter!=buffer.end() and iter->first<S[i-1]){
possible.insert((iter++)->second);
}
int r = i-1;
for(int jump=131072;jump;jump/=2){
if(r-jump<0)continue;
if(S[r-jump]>=S[i-1]-arr[i])r-=jump;
}
auto iter2 = possible.lower_bound(r);
DP[i]=1;
for(auto iter3=possible.begin();iter3!=iter2;iter3++){
int j = *iter3;
DP[i]=max(DP[i],DP[j]+2);
}
}
int ans = DP[n];
int sum = arr[n];
for(int i=n-1;i;i--){
if(arr[i]<sum)ans=max(ans,DP[i]+1);
sum+=arr[i];
}
cout << ans << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> L(n+1);
for(int i=1;i<=n;i++)cin>>L[i];
int q;
cin >> q;
for(int i=1;i<=q;i++){
int x,y,a,b;cin>>x>>y>>a>>b;
L[x]=y;
vector<int> arr;
for(int j=a+1;j<=b;j++){
arr.emplace_back(L[j]);
}
answer(arr);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
21 ms |
680 KB |
Output is correct |
27 |
Correct |
16 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
684 KB |
Output is correct |
29 |
Correct |
16 ms |
628 KB |
Output is correct |
30 |
Correct |
14 ms |
604 KB |
Output is correct |
31 |
Correct |
14 ms |
600 KB |
Output is correct |
32 |
Correct |
12 ms |
604 KB |
Output is correct |
33 |
Correct |
11 ms |
644 KB |
Output is correct |
34 |
Correct |
16 ms |
656 KB |
Output is correct |
35 |
Correct |
18 ms |
604 KB |
Output is correct |
36 |
Correct |
8 ms |
564 KB |
Output is correct |
37 |
Correct |
24 ms |
600 KB |
Output is correct |
38 |
Correct |
8 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
21 ms |
680 KB |
Output is correct |
27 |
Correct |
16 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
684 KB |
Output is correct |
29 |
Correct |
16 ms |
628 KB |
Output is correct |
30 |
Correct |
14 ms |
604 KB |
Output is correct |
31 |
Correct |
14 ms |
600 KB |
Output is correct |
32 |
Correct |
12 ms |
604 KB |
Output is correct |
33 |
Correct |
11 ms |
644 KB |
Output is correct |
34 |
Correct |
16 ms |
656 KB |
Output is correct |
35 |
Correct |
18 ms |
604 KB |
Output is correct |
36 |
Correct |
8 ms |
564 KB |
Output is correct |
37 |
Correct |
24 ms |
600 KB |
Output is correct |
38 |
Correct |
8 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
560 KB |
Output is correct |
41 |
Correct |
16 ms |
3920 KB |
Output is correct |
42 |
Correct |
19 ms |
4440 KB |
Output is correct |
43 |
Correct |
104 ms |
4584 KB |
Output is correct |
44 |
Correct |
765 ms |
5076 KB |
Output is correct |
45 |
Execution timed out |
4045 ms |
10500 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
685 ms |
4908 KB |
Output is correct |
3 |
Execution timed out |
4051 ms |
5312 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
595 ms |
4824 KB |
Output is correct |
4 |
Execution timed out |
4027 ms |
4564 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
21 ms |
680 KB |
Output is correct |
27 |
Correct |
16 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
684 KB |
Output is correct |
29 |
Correct |
16 ms |
628 KB |
Output is correct |
30 |
Correct |
14 ms |
604 KB |
Output is correct |
31 |
Correct |
14 ms |
600 KB |
Output is correct |
32 |
Correct |
12 ms |
604 KB |
Output is correct |
33 |
Correct |
11 ms |
644 KB |
Output is correct |
34 |
Correct |
16 ms |
656 KB |
Output is correct |
35 |
Correct |
18 ms |
604 KB |
Output is correct |
36 |
Correct |
8 ms |
564 KB |
Output is correct |
37 |
Correct |
24 ms |
600 KB |
Output is correct |
38 |
Correct |
8 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
560 KB |
Output is correct |
41 |
Correct |
16 ms |
3920 KB |
Output is correct |
42 |
Correct |
19 ms |
4440 KB |
Output is correct |
43 |
Correct |
104 ms |
4584 KB |
Output is correct |
44 |
Correct |
765 ms |
5076 KB |
Output is correct |
45 |
Execution timed out |
4045 ms |
10500 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |