Submission #99179

# Submission time Handle Problem Language Result Execution time Memory
99179 2019-03-01T14:06:56 Z bharat2002 Global Warming (CEOI18_glo) C++14
100 / 100
128 ms 8772 KB
/*input
9 4
5 6 7 1 2 3 11 12 13
*/
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
stack< pii > updatestolis;int lis[N], lds[N], arr[N], n, x, ans, l2;
void clis()
{
	int len=1;lis[0]=0;
	for(int i=1;i<=n;i++)
	{
		pii add;
		if(arr[i]<lis[1])
		{
			add=mp(1, lis[1]);
			lis[1]=arr[i];
		}
		else if(arr[i]>lis[len-1])
		{
			add=mp(len, 1e17);lis[len++]=arr[i];
		}
		else
		{
			int low=1, high=len-1;
			while(low<high)
			{
				int mid=(low+high)>>1;
				if(lis[mid]>=arr[i]) high=mid;
				else low=mid+1;
			}
			add=mp(low, lis[low]);lis[low]=arr[i];
		}
		updatestolis.push(add);
	}
	ans=len-1;l2=len;
	for(int i=len;i<=n;i++) lis[i]=1e17;
}
void clds()
{
	int len=1;lds[0]=lds[1]=1e17;
	for(int i=n;i>=1;i--)
	{
		int add;
		if(arr[i]>lds[1])
		{
			lds[1]=arr[i];add=1;
		}
		else if(arr[i]<lds[len-1])
		{
			lds[len++]=arr[i];add=len-1;
		}
		else
		{
			int low=1, high=len-1;
			while(low<high)
			{
				int mid=(low+high)>>1;
				if(lds[mid]<=arr[i]) high=mid;
				else low=mid+1;
			}
			lds[low]=arr[i];add=low;
		}
		pii temp=updatestolis.top();updatestolis.pop();
		lis[temp.f]=temp.s;
		int low=1, high=n;
		while(low<high)
		{
			int mid=(low+high+1)/2;
			if(lis[mid] - arr[i]<x) low=mid;
			else high=mid-1;
		}		
		if(lis[low] - arr[i]>=x) low=0;
//		cout<<low<<" "<<add<<endl;
		ans=max(ans, low + add);
	}
	assert(len==l2);
	for(int i=len;i<=n;i++) lis[i]=1e17;
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	clis();clds();cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 6856 KB Output is correct
2 Correct 77 ms 8668 KB Output is correct
3 Correct 128 ms 8716 KB Output is correct
4 Correct 92 ms 8696 KB Output is correct
5 Correct 62 ms 7928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1920 KB Output is correct
2 Correct 21 ms 2432 KB Output is correct
3 Correct 23 ms 2424 KB Output is correct
4 Correct 14 ms 2276 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 24 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3576 KB Output is correct
2 Correct 32 ms 3600 KB Output is correct
3 Correct 66 ms 6784 KB Output is correct
4 Correct 47 ms 6784 KB Output is correct
5 Correct 32 ms 3580 KB Output is correct
6 Correct 43 ms 6520 KB Output is correct
7 Correct 46 ms 6524 KB Output is correct
8 Correct 35 ms 3704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 111 ms 6856 KB Output is correct
28 Correct 77 ms 8668 KB Output is correct
29 Correct 128 ms 8716 KB Output is correct
30 Correct 92 ms 8696 KB Output is correct
31 Correct 62 ms 7928 KB Output is correct
32 Correct 22 ms 1920 KB Output is correct
33 Correct 21 ms 2432 KB Output is correct
34 Correct 23 ms 2424 KB Output is correct
35 Correct 14 ms 2276 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 16 ms 2304 KB Output is correct
38 Correct 24 ms 2432 KB Output is correct
39 Correct 33 ms 3576 KB Output is correct
40 Correct 32 ms 3600 KB Output is correct
41 Correct 66 ms 6784 KB Output is correct
42 Correct 47 ms 6784 KB Output is correct
43 Correct 32 ms 3580 KB Output is correct
44 Correct 43 ms 6520 KB Output is correct
45 Correct 46 ms 6524 KB Output is correct
46 Correct 35 ms 3704 KB Output is correct
47 Correct 36 ms 4480 KB Output is correct
48 Correct 37 ms 4608 KB Output is correct
49 Correct 77 ms 8696 KB Output is correct
50 Correct 58 ms 7928 KB Output is correct
51 Correct 39 ms 6296 KB Output is correct
52 Correct 54 ms 8056 KB Output is correct
53 Correct 46 ms 8016 KB Output is correct
54 Correct 51 ms 8772 KB Output is correct
55 Correct 70 ms 8696 KB Output is correct