#include <bits/stdc++.h>
using namespace std;
#define int long long
struct segtree{
vector<int> tree;
segtree():tree(524288){}
void update(int k,int x){
k+=262144;
tree[k]=x;
while(k/=2){
tree[k]=max(tree[2*k],tree[2*k+1]);
}
}
int get(int l,int r){
l+=262144;r+=262144;
int ans = 0;
while(l<=r){
if(l&1)ans=max(ans,tree[l++]);
if(r%2==0)ans=max(ans,tree[r--]);
l/=2;r/=2;
}
return ans;
}
};
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();
vector<int> DP(n+1);
segtree seg;
for(int i=1;i<=n;i++){
while(iter!=buffer.end() and iter->first<S[i-1]){
seg.update(iter->second,DP[iter->second]);
iter++;
}
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;
}
DP[i]=1;
if(r==0)continue;
DP[i]=max(DP[i],seg.get(0,r-1)+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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
4 ms |
4520 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
4 ms |
4552 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4488 KB |
Output is correct |
7 |
Correct |
5 ms |
4440 KB |
Output is correct |
8 |
Correct |
4 ms |
4592 KB |
Output is correct |
9 |
Correct |
5 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
4 ms |
4440 KB |
Output is correct |
14 |
Correct |
4 ms |
4440 KB |
Output is correct |
15 |
Correct |
4 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
4540 KB |
Output is correct |
17 |
Correct |
4 ms |
4600 KB |
Output is correct |
18 |
Correct |
4 ms |
4556 KB |
Output is correct |
19 |
Correct |
6 ms |
4560 KB |
Output is correct |
20 |
Correct |
4 ms |
4356 KB |
Output is correct |
21 |
Correct |
4 ms |
4540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
4 ms |
4520 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
4 ms |
4552 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4488 KB |
Output is correct |
7 |
Correct |
5 ms |
4440 KB |
Output is correct |
8 |
Correct |
4 ms |
4592 KB |
Output is correct |
9 |
Correct |
5 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
4 ms |
4440 KB |
Output is correct |
14 |
Correct |
4 ms |
4440 KB |
Output is correct |
15 |
Correct |
4 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
4540 KB |
Output is correct |
17 |
Correct |
4 ms |
4600 KB |
Output is correct |
18 |
Correct |
4 ms |
4556 KB |
Output is correct |
19 |
Correct |
6 ms |
4560 KB |
Output is correct |
20 |
Correct |
4 ms |
4356 KB |
Output is correct |
21 |
Correct |
4 ms |
4540 KB |
Output is correct |
22 |
Correct |
6 ms |
4440 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
4 ms |
4632 KB |
Output is correct |
25 |
Correct |
5 ms |
4444 KB |
Output is correct |
26 |
Correct |
6 ms |
4692 KB |
Output is correct |
27 |
Correct |
7 ms |
4696 KB |
Output is correct |
28 |
Correct |
5 ms |
4572 KB |
Output is correct |
29 |
Correct |
5 ms |
4696 KB |
Output is correct |
30 |
Correct |
5 ms |
4696 KB |
Output is correct |
31 |
Correct |
5 ms |
4552 KB |
Output is correct |
32 |
Correct |
5 ms |
4692 KB |
Output is correct |
33 |
Correct |
5 ms |
4696 KB |
Output is correct |
34 |
Correct |
5 ms |
4444 KB |
Output is correct |
35 |
Correct |
5 ms |
4696 KB |
Output is correct |
36 |
Correct |
4 ms |
4444 KB |
Output is correct |
37 |
Correct |
5 ms |
4696 KB |
Output is correct |
38 |
Correct |
4 ms |
4444 KB |
Output is correct |
39 |
Correct |
4 ms |
4444 KB |
Output is correct |
40 |
Correct |
4 ms |
4584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
4 ms |
4520 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
4 ms |
4552 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4488 KB |
Output is correct |
7 |
Correct |
5 ms |
4440 KB |
Output is correct |
8 |
Correct |
4 ms |
4592 KB |
Output is correct |
9 |
Correct |
5 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
4 ms |
4440 KB |
Output is correct |
14 |
Correct |
4 ms |
4440 KB |
Output is correct |
15 |
Correct |
4 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
4540 KB |
Output is correct |
17 |
Correct |
4 ms |
4600 KB |
Output is correct |
18 |
Correct |
4 ms |
4556 KB |
Output is correct |
19 |
Correct |
6 ms |
4560 KB |
Output is correct |
20 |
Correct |
4 ms |
4356 KB |
Output is correct |
21 |
Correct |
4 ms |
4540 KB |
Output is correct |
22 |
Correct |
6 ms |
4440 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
4 ms |
4632 KB |
Output is correct |
25 |
Correct |
5 ms |
4444 KB |
Output is correct |
26 |
Correct |
6 ms |
4692 KB |
Output is correct |
27 |
Correct |
7 ms |
4696 KB |
Output is correct |
28 |
Correct |
5 ms |
4572 KB |
Output is correct |
29 |
Correct |
5 ms |
4696 KB |
Output is correct |
30 |
Correct |
5 ms |
4696 KB |
Output is correct |
31 |
Correct |
5 ms |
4552 KB |
Output is correct |
32 |
Correct |
5 ms |
4692 KB |
Output is correct |
33 |
Correct |
5 ms |
4696 KB |
Output is correct |
34 |
Correct |
5 ms |
4444 KB |
Output is correct |
35 |
Correct |
5 ms |
4696 KB |
Output is correct |
36 |
Correct |
4 ms |
4444 KB |
Output is correct |
37 |
Correct |
5 ms |
4696 KB |
Output is correct |
38 |
Correct |
4 ms |
4444 KB |
Output is correct |
39 |
Correct |
4 ms |
4444 KB |
Output is correct |
40 |
Correct |
4 ms |
4584 KB |
Output is correct |
41 |
Correct |
19 ms |
8260 KB |
Output is correct |
42 |
Correct |
19 ms |
8552 KB |
Output is correct |
43 |
Correct |
26 ms |
8644 KB |
Output is correct |
44 |
Correct |
19 ms |
8580 KB |
Output is correct |
45 |
Correct |
66 ms |
15160 KB |
Output is correct |
46 |
Correct |
198 ms |
19800 KB |
Output is correct |
47 |
Correct |
153 ms |
16716 KB |
Output is correct |
48 |
Correct |
225 ms |
20060 KB |
Output is correct |
49 |
Correct |
293 ms |
19792 KB |
Output is correct |
50 |
Correct |
196 ms |
17320 KB |
Output is correct |
51 |
Correct |
172 ms |
19316 KB |
Output is correct |
52 |
Correct |
111 ms |
17368 KB |
Output is correct |
53 |
Correct |
251 ms |
18996 KB |
Output is correct |
54 |
Correct |
259 ms |
18032 KB |
Output is correct |
55 |
Correct |
199 ms |
20492 KB |
Output is correct |
56 |
Correct |
176 ms |
17480 KB |
Output is correct |
57 |
Correct |
110 ms |
12992 KB |
Output is correct |
58 |
Correct |
187 ms |
18136 KB |
Output is correct |
59 |
Correct |
55 ms |
17232 KB |
Output is correct |
60 |
Correct |
81 ms |
14284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4444 KB |
Output is correct |
2 |
Execution timed out |
4091 ms |
9228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
5 ms |
4548 KB |
Output is correct |
3 |
Execution timed out |
4056 ms |
8888 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
4 ms |
4520 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
4 ms |
4552 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4488 KB |
Output is correct |
7 |
Correct |
5 ms |
4440 KB |
Output is correct |
8 |
Correct |
4 ms |
4592 KB |
Output is correct |
9 |
Correct |
5 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
4 ms |
4440 KB |
Output is correct |
14 |
Correct |
4 ms |
4440 KB |
Output is correct |
15 |
Correct |
4 ms |
4444 KB |
Output is correct |
16 |
Correct |
4 ms |
4540 KB |
Output is correct |
17 |
Correct |
4 ms |
4600 KB |
Output is correct |
18 |
Correct |
4 ms |
4556 KB |
Output is correct |
19 |
Correct |
6 ms |
4560 KB |
Output is correct |
20 |
Correct |
4 ms |
4356 KB |
Output is correct |
21 |
Correct |
4 ms |
4540 KB |
Output is correct |
22 |
Correct |
6 ms |
4440 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
4 ms |
4632 KB |
Output is correct |
25 |
Correct |
5 ms |
4444 KB |
Output is correct |
26 |
Correct |
6 ms |
4692 KB |
Output is correct |
27 |
Correct |
7 ms |
4696 KB |
Output is correct |
28 |
Correct |
5 ms |
4572 KB |
Output is correct |
29 |
Correct |
5 ms |
4696 KB |
Output is correct |
30 |
Correct |
5 ms |
4696 KB |
Output is correct |
31 |
Correct |
5 ms |
4552 KB |
Output is correct |
32 |
Correct |
5 ms |
4692 KB |
Output is correct |
33 |
Correct |
5 ms |
4696 KB |
Output is correct |
34 |
Correct |
5 ms |
4444 KB |
Output is correct |
35 |
Correct |
5 ms |
4696 KB |
Output is correct |
36 |
Correct |
4 ms |
4444 KB |
Output is correct |
37 |
Correct |
5 ms |
4696 KB |
Output is correct |
38 |
Correct |
4 ms |
4444 KB |
Output is correct |
39 |
Correct |
4 ms |
4444 KB |
Output is correct |
40 |
Correct |
4 ms |
4584 KB |
Output is correct |
41 |
Correct |
19 ms |
8260 KB |
Output is correct |
42 |
Correct |
19 ms |
8552 KB |
Output is correct |
43 |
Correct |
26 ms |
8644 KB |
Output is correct |
44 |
Correct |
19 ms |
8580 KB |
Output is correct |
45 |
Correct |
66 ms |
15160 KB |
Output is correct |
46 |
Correct |
198 ms |
19800 KB |
Output is correct |
47 |
Correct |
153 ms |
16716 KB |
Output is correct |
48 |
Correct |
225 ms |
20060 KB |
Output is correct |
49 |
Correct |
293 ms |
19792 KB |
Output is correct |
50 |
Correct |
196 ms |
17320 KB |
Output is correct |
51 |
Correct |
172 ms |
19316 KB |
Output is correct |
52 |
Correct |
111 ms |
17368 KB |
Output is correct |
53 |
Correct |
251 ms |
18996 KB |
Output is correct |
54 |
Correct |
259 ms |
18032 KB |
Output is correct |
55 |
Correct |
199 ms |
20492 KB |
Output is correct |
56 |
Correct |
176 ms |
17480 KB |
Output is correct |
57 |
Correct |
110 ms |
12992 KB |
Output is correct |
58 |
Correct |
187 ms |
18136 KB |
Output is correct |
59 |
Correct |
55 ms |
17232 KB |
Output is correct |
60 |
Correct |
81 ms |
14284 KB |
Output is correct |
61 |
Correct |
3 ms |
4444 KB |
Output is correct |
62 |
Execution timed out |
4091 ms |
9228 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |