답안 #1016409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016409 2024-07-08T04:39:49 Z vjudge1 Global Warming (CEOI18_glo) C++17
100 / 100
213 ms 11856 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()

int dp[2][200010];
int tree[2][800010];

void update1(int idx,int l,int r,int x,int v)
{
	if(l==r)
	{
		tree[0][idx]=v;
		return;
	}

	int mid=(l+r)/2;
	if(x<=mid) update1(idx*2,l,mid,x,v);
	else update1(idx*2+1,mid+1,r,x,v);
	tree[0][idx]=max(tree[0][idx*2],tree[0][idx*2+1]);
}

void update2(int idx,int l,int r,int x,int v)
{
	if(l==r)
	{
		tree[1][idx]=v;
		return;
	}

	int mid=(l+r)/2;
	if(x<=mid) update2(idx*2,l,mid,x,v);
	else update2(idx*2+1,mid+1,r,x,v);
	tree[1][idx]=max(tree[1][idx*2],tree[1][idx*2+1]);
}

int query1(int idx,int l,int r,int x,int y)
{
	if(x<=l && r<=y) return tree[0][idx];
	if(r<x || y<l) return 0;

	int mid=(l+r)/2;
	return max(query1(idx*2,l,mid,x,y),query1(idx*2+1,mid+1,r,x,y));
}

int query2(int idx,int l,int r,int x,int y)
{
	if(x<=l && r<=y) return tree[1][idx];
	if(r<x || y<l) return 0;

	int mid=(l+r)/2;
	return max(query2(idx*2,l,mid,x,y),query2(idx*2+1,mid+1,r,x,y));
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n,x;cin>>n>>x;
	vector<int> a(n+1),b;
	for(int i=1;i<=n;i++) cin>>a[i];
	a[0]=-1;
	b=a;
	sort(all(b));
	b.erase(unique(all(b)),b.end());
	int m=b.size();
	m--;

	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int pos=lower_bound(all(b),a[i])-b.begin();
		int pos2=lower_bound(all(b),a[i]+x)-b.begin();
		if(i==1) dp[0][i]=dp[1][i]=1;
		else
		{
			dp[0][i]=query1(1,1,m,1,pos-1)+1;
			dp[1][i]=max(query1(1,1,m,1,pos2-1),query2(1,1,m,1,pos-1))+1;
		}
		update1(1,1,m,pos,dp[0][i]);
		update2(1,1,m,pos,dp[1][i]);
		ans=max(ans,max(dp[0][i],dp[1][i]));
		// for(int j=1;j<=n;j++) debug(query1(1,1,m,j,j));
		// for(int j=1;j<=n;j++) debug(query2(1,1,m,j,j));
	}
	cout<<ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4564 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4564 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 11628 KB Output is correct
2 Correct 199 ms 11608 KB Output is correct
3 Correct 208 ms 11712 KB Output is correct
4 Correct 212 ms 11604 KB Output is correct
5 Correct 100 ms 10968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 7772 KB Output is correct
2 Correct 45 ms 7760 KB Output is correct
3 Correct 45 ms 7764 KB Output is correct
4 Correct 24 ms 5648 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 25 ms 5700 KB Output is correct
7 Correct 39 ms 7900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 9116 KB Output is correct
2 Correct 77 ms 9068 KB Output is correct
3 Correct 166 ms 11604 KB Output is correct
4 Correct 89 ms 10836 KB Output is correct
5 Correct 51 ms 8784 KB Output is correct
6 Correct 85 ms 10832 KB Output is correct
7 Correct 115 ms 11348 KB Output is correct
8 Correct 65 ms 9064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4564 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4560 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 213 ms 11628 KB Output is correct
28 Correct 199 ms 11608 KB Output is correct
29 Correct 208 ms 11712 KB Output is correct
30 Correct 212 ms 11604 KB Output is correct
31 Correct 100 ms 10968 KB Output is correct
32 Correct 45 ms 7772 KB Output is correct
33 Correct 45 ms 7760 KB Output is correct
34 Correct 45 ms 7764 KB Output is correct
35 Correct 24 ms 5648 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 25 ms 5700 KB Output is correct
38 Correct 39 ms 7900 KB Output is correct
39 Correct 78 ms 9116 KB Output is correct
40 Correct 77 ms 9068 KB Output is correct
41 Correct 166 ms 11604 KB Output is correct
42 Correct 89 ms 10836 KB Output is correct
43 Correct 51 ms 8784 KB Output is correct
44 Correct 85 ms 10832 KB Output is correct
45 Correct 115 ms 11348 KB Output is correct
46 Correct 65 ms 9064 KB Output is correct
47 Correct 95 ms 9116 KB Output is correct
48 Correct 97 ms 9060 KB Output is correct
49 Correct 191 ms 11856 KB Output is correct
50 Correct 117 ms 10836 KB Output is correct
51 Correct 91 ms 9808 KB Output is correct
52 Correct 115 ms 11088 KB Output is correct
53 Correct 99 ms 11084 KB Output is correct
54 Correct 92 ms 11604 KB Output is correct
55 Correct 153 ms 11600 KB Output is correct