Submission #706811

# Submission time Handle Problem Language Result Execution time Memory
706811 2023-03-07T20:19:53 Z amirhoseinfar1385 Global Warming (CEOI18_glo) C++17
100 / 100
172 ms 9292 KB
#include<bits/stdc++.h>
using namespace std;
int n,x;
vector<int>all,allind;
int kaf=(1<<19);

struct segment{
	int seg[(1<<20)];
	segment(){
		for(int i=0;i<(1<<20);i++){
			seg[i]=0;
		}
	}
	void upd(int i,int w){
		if(i==0){
			return ;
		}
		seg[i]=max(seg[i],w);
		return upd((i>>1),w);
	}
	int pors(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl){
			return 0;
		}
		if(l>=tl&&r<=tr){
			return seg[i];
		}
		int m=(l+r)>>1;
		int d=max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
		return d;
	}
};
segment seg;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>x;
	all.resize(n);
	for(int i=0;i<n;i++){
		cin>>all[i];
	}
	allind=all;
	sort(allind.begin(),allind.end());
	allind.resize(unique(allind.begin(),allind.end())-allind.begin());
	vector<int>dp(n+1);
	for(int i=0;i<n;i++){
		all[i]=-all[i];
	}
	vector<int>v;
	for(int i=n-1;i>=0;i--){
		int p=lower_bound(v.begin(),v.end(),all[i])-v.begin();
		if((int)v.size()==p){
			v.push_back(all[i]);
		}
		else{
			v[p]=all[i];
		}
		dp[i]=p+1;
	//	cout<<i<<" "<<dp[i]<<"\n";
	}
	for(int i=0;i<n;i++){
		all[i]=-all[i];
	}
	int res=0;
	for(int i=0;i<n;i++){
		int p=upper_bound(allind.begin(),allind.end(),all[i]+x-1)-allind.begin();
		p--;
		int wtf=seg.pors(1,0,kaf-1,0,p);
		//cout<<i<<" "<<wtf<<" "<<dp[i]<<"\n";
		res=max(res,wtf+dp[i]);
		p=lower_bound(allind.begin(),allind.end(),all[i])-allind.begin();
		wtf=seg.pors(1,0,kaf-1,0,p-1);
		wtf++;
		seg.upd(kaf+p,wtf);
	}
	cout<<res<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4420 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4424 KB Output is correct
8 Correct 2 ms 4428 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4424 KB Output is correct
11 Correct 2 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4420 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4424 KB Output is correct
8 Correct 2 ms 4428 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4424 KB Output is correct
11 Correct 2 ms 4428 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 3 ms 4424 KB Output is correct
15 Correct 2 ms 4420 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4420 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4424 KB Output is correct
8 Correct 2 ms 4428 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4424 KB Output is correct
11 Correct 2 ms 4428 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 3 ms 4424 KB Output is correct
15 Correct 2 ms 4420 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 3 ms 4428 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4436 KB Output is correct
23 Correct 4 ms 4424 KB Output is correct
24 Correct 3 ms 4428 KB Output is correct
25 Correct 3 ms 4436 KB Output is correct
26 Correct 2 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 8656 KB Output is correct
2 Correct 152 ms 8700 KB Output is correct
3 Correct 164 ms 8700 KB Output is correct
4 Correct 151 ms 8652 KB Output is correct
5 Correct 80 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5504 KB Output is correct
2 Correct 39 ms 5460 KB Output is correct
3 Correct 41 ms 5480 KB Output is correct
4 Correct 21 ms 5508 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 22 ms 5460 KB Output is correct
7 Correct 38 ms 5440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 6480 KB Output is correct
2 Correct 64 ms 6564 KB Output is correct
3 Correct 128 ms 8640 KB Output is correct
4 Correct 90 ms 8548 KB Output is correct
5 Correct 41 ms 6480 KB Output is correct
6 Correct 67 ms 8488 KB Output is correct
7 Correct 74 ms 9132 KB Output is correct
8 Correct 55 ms 6584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4420 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4424 KB Output is correct
8 Correct 2 ms 4428 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4424 KB Output is correct
11 Correct 2 ms 4428 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 3 ms 4424 KB Output is correct
15 Correct 2 ms 4420 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 2 ms 4308 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 3 ms 4428 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4436 KB Output is correct
23 Correct 4 ms 4424 KB Output is correct
24 Correct 3 ms 4428 KB Output is correct
25 Correct 3 ms 4436 KB Output is correct
26 Correct 2 ms 4436 KB Output is correct
27 Correct 157 ms 8656 KB Output is correct
28 Correct 152 ms 8700 KB Output is correct
29 Correct 164 ms 8700 KB Output is correct
30 Correct 151 ms 8652 KB Output is correct
31 Correct 80 ms 8524 KB Output is correct
32 Correct 39 ms 5504 KB Output is correct
33 Correct 39 ms 5460 KB Output is correct
34 Correct 41 ms 5480 KB Output is correct
35 Correct 21 ms 5508 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 22 ms 5460 KB Output is correct
38 Correct 38 ms 5440 KB Output is correct
39 Correct 62 ms 6480 KB Output is correct
40 Correct 64 ms 6564 KB Output is correct
41 Correct 128 ms 8640 KB Output is correct
42 Correct 90 ms 8548 KB Output is correct
43 Correct 41 ms 6480 KB Output is correct
44 Correct 67 ms 8488 KB Output is correct
45 Correct 74 ms 9132 KB Output is correct
46 Correct 55 ms 6584 KB Output is correct
47 Correct 76 ms 6560 KB Output is correct
48 Correct 75 ms 6556 KB Output is correct
49 Correct 172 ms 8704 KB Output is correct
50 Correct 82 ms 8532 KB Output is correct
51 Correct 71 ms 7700 KB Output is correct
52 Correct 101 ms 8656 KB Output is correct
53 Correct 73 ms 8656 KB Output is correct
54 Correct 84 ms 9292 KB Output is correct
55 Correct 131 ms 8644 KB Output is correct