Submission #1094109

# Submission time Handle Problem Language Result Execution time Memory
1094109 2024-09-28T12:32:17 Z alexander707070 Global Warming (CEOI18_glo) C++14
100 / 100
298 ms 122020 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;
 
const long long inf=1e9;
 
struct ST{
	struct node{
		int l,r,val;
	};
 
	node tree[100*MAXN];
	int num;
	
	void init(){
		num=1;
		tree[num]={0,0,0};
	}
 
	void addnode(){
		num++;
		tree[num]={0,0,0};
	}
 
	void check(int v){
		if(tree[v].l==0){
			addnode(); tree[v].l=num;
		}
 
		if(tree[v].r==0){
			addnode(); tree[v].r=num;
		}
	}
 
	void update(int v,long long l,long long r,long long pos,int val){
		if(l==r){
			tree[v].val=max(tree[v].val,val);
		}else{
			long long tt=(l+r)/2;
			check(v);
 
			if(pos<=tt)update(tree[v].l,l,tt,pos,val);
			else update(tree[v].r,tt+1,r,pos,val);
 
			tree[v].val=max(tree[tree[v].l].val,tree[tree[v].r].val);
		}
	}
 
	int getmax(int v,long long l,long long r,long long ll,long long rr){
		if(ll>rr or v==0)return 0;
		if(l==ll and r==rr){
			return tree[v].val;
		}else{
			long long tt=(l+r)/2;
			return max( getmax(tree[v].l,l,tt,ll,min(tt,rr)) , getmax(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
		}
	}
}seg[3];
 
int n,a[MAXN],ans,x;
int dp[MAXN][3];
 
int solve(){
	seg[0].init();
	seg[1].init();

	int res=0;
	for(int i=1;i<=n;i++){
		dp[i][0]=seg[0].getmax(1,0,2*inf,0,a[i]-1)+1;
		seg[0].update(1,0,2*inf,a[i],dp[i][0]);
	}

	for(int i=n;i>=1;i--){
		dp[i][1]=seg[1].getmax(1,0,2*inf,a[i]+1,2*inf)+1;
		seg[1].update(1,0,2*inf,a[i],dp[i][1]);

		res=max(res,dp[i-1][0]+seg[1].getmax(1,0,2*inf,a[i-1]-x+1,2*inf));
	}

	return res;
}
 
int main(){
 
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	cin>>n>>x;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=inf;
	}
 
	cout<<solve()<<"\n";
 
    return 0;
}
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1368 KB Output is correct
21 Correct 2 ms 1368 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 121988 KB Output is correct
2 Correct 297 ms 121944 KB Output is correct
3 Correct 298 ms 121828 KB Output is correct
4 Correct 296 ms 121940 KB Output is correct
5 Correct 176 ms 67608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 35412 KB Output is correct
2 Correct 66 ms 35408 KB Output is correct
3 Correct 65 ms 35408 KB Output is correct
4 Correct 45 ms 19540 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 43 ms 3880 KB Output is correct
7 Correct 57 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 65876 KB Output is correct
2 Correct 124 ms 65780 KB Output is correct
3 Correct 266 ms 121936 KB Output is correct
4 Correct 156 ms 67668 KB Output is correct
5 Correct 70 ms 7252 KB Output is correct
6 Correct 128 ms 13396 KB Output is correct
7 Correct 130 ms 14220 KB Output is correct
8 Correct 96 ms 46416 KB Output is correct
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1368 KB Output is correct
21 Correct 2 ms 1368 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 294 ms 121988 KB Output is correct
28 Correct 297 ms 121944 KB Output is correct
29 Correct 298 ms 121828 KB Output is correct
30 Correct 296 ms 121940 KB Output is correct
31 Correct 176 ms 67608 KB Output is correct
32 Correct 63 ms 35412 KB Output is correct
33 Correct 66 ms 35408 KB Output is correct
34 Correct 65 ms 35408 KB Output is correct
35 Correct 45 ms 19540 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 43 ms 3880 KB Output is correct
38 Correct 57 ms 24916 KB Output is correct
39 Correct 122 ms 65876 KB Output is correct
40 Correct 124 ms 65780 KB Output is correct
41 Correct 266 ms 121936 KB Output is correct
42 Correct 156 ms 67668 KB Output is correct
43 Correct 70 ms 7252 KB Output is correct
44 Correct 128 ms 13396 KB Output is correct
45 Correct 130 ms 14220 KB Output is correct
46 Correct 96 ms 46416 KB Output is correct
47 Correct 131 ms 65876 KB Output is correct
48 Correct 131 ms 65724 KB Output is correct
49 Correct 280 ms 122020 KB Output is correct
50 Correct 159 ms 67664 KB Output is correct
51 Correct 103 ms 8124 KB Output is correct
52 Correct 163 ms 14160 KB Output is correct
53 Correct 143 ms 14160 KB Output is correct
54 Correct 137 ms 14928 KB Output is correct
55 Correct 232 ms 86356 KB Output is correct