답안 #704149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704149 2023-03-01T17:24:24 Z KLPP Global Warming (CEOI18_glo) C++14
100 / 100
110 ms 10944 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

class FT{
	vector<lld> F;
	public:
	void init(int n){
		F.clear();
		F.resize(n+1,-1e18);
	}
	void update(int pos, lld val){
		pos++;
		if(pos==0)return;
		for(;pos<(int)F.size();pos+=(pos&(-pos))){
			F[pos]=max(F[pos],val);
		}
	}
	lld query(int pos){
		pos++;
		if(pos==0)return -1e18;
		lld ans=-1e18;
		for(;pos>0;pos-=(pos&(-pos))){
			//cout<<"A"<<" "<<pos<<endl;
			ans=max(ans,F[pos]);
		}
		return ans;
	}
};
FT F;
void solve(){
	/*freopen("talent.in", "r", stdin);
	freopen("talent.out", "w", stdout);*/
	int n;
	lld x;
	cin>>n>>x;
	vector<lld> V(n);
	for(auto &y:V)cin>>y;
	vector<lld> L;
	vector<lld> pref(n),suf(n);
	auto apply=[&](vector<lld> &obj, bool invert){
		L.clear();
		rep(i,0,n){
			int lo=-1;
			int hi=L.size();
			while(hi-lo>1){
				int mid=(hi+lo)/2;
				if(!invert){
					if(L[mid]<V[i])lo=mid;
					else hi=mid;
				}else{
					if(L[mid]>V[i])lo=mid;
					else hi=mid;
				}
			}
			if(hi==(int)L.size())L.push_back(V[i]);
			L[hi]=V[i];
			obj[i]=hi+1;
		}
		return;
	};
	apply(pref,0);
	reverse(V.begin(),V.end());
	apply(suf,1);
	reverse(V.begin(),V.end());
	reverse(suf.begin(),suf.end());
	lld ans=(int)L.size();
	vector<lld> comp;
	trav(a,V)comp.push_back(a);
	sort(comp.begin(),comp.end());
	comp.resize(unique(comp.begin(),comp.end())-comp.begin());
	F.init(comp.size());
	//trav(a,comp)cout<<a<<"\n";
	rep(i,0,n){
		//cout<<V[i]+x<<" "<<lower_bound(comp.begin(),comp.end(),V[i]+x)-comp.begin()-1<<" "<<F.query(upper_bound(comp.begin(),comp.end(),V[i]+x)-comp.begin()-1)<<" "<<suf[i]<<endl;
		ans=max(ans,F.query(lower_bound(comp.begin(),comp.end(),V[i]+x)-comp.begin()-1)+suf[i]);
		F.update(lower_bound(comp.begin(),comp.end(),V[i])-comp.begin(),pref[i]);
		//cout<<lower_bound(comp.begin(),comp.end(),V[i])-comp.begin()<<" "<<pref[i]<<endl;
	}
	cout<<ans<<"\n";
}
	

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.precision(16);
	int tt=1;
	//cin>>tt;
	rep(test,0,tt){
		solve();
	}
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 10196 KB Output is correct
2 Correct 107 ms 10164 KB Output is correct
3 Correct 108 ms 10176 KB Output is correct
4 Correct 109 ms 10180 KB Output is correct
5 Correct 73 ms 9288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2900 KB Output is correct
2 Correct 25 ms 2900 KB Output is correct
3 Correct 25 ms 2912 KB Output is correct
4 Correct 19 ms 2536 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 22 ms 2876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 5320 KB Output is correct
2 Correct 48 ms 5312 KB Output is correct
3 Correct 92 ms 10208 KB Output is correct
4 Correct 73 ms 9236 KB Output is correct
5 Correct 35 ms 5352 KB Output is correct
6 Correct 58 ms 9800 KB Output is correct
7 Correct 63 ms 10440 KB Output is correct
8 Correct 38 ms 5320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 110 ms 10196 KB Output is correct
28 Correct 107 ms 10164 KB Output is correct
29 Correct 108 ms 10176 KB Output is correct
30 Correct 109 ms 10180 KB Output is correct
31 Correct 73 ms 9288 KB Output is correct
32 Correct 25 ms 2900 KB Output is correct
33 Correct 25 ms 2900 KB Output is correct
34 Correct 25 ms 2912 KB Output is correct
35 Correct 19 ms 2536 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 17 ms 2636 KB Output is correct
38 Correct 22 ms 2876 KB Output is correct
39 Correct 45 ms 5320 KB Output is correct
40 Correct 48 ms 5312 KB Output is correct
41 Correct 92 ms 10208 KB Output is correct
42 Correct 73 ms 9236 KB Output is correct
43 Correct 35 ms 5352 KB Output is correct
44 Correct 58 ms 9800 KB Output is correct
45 Correct 63 ms 10440 KB Output is correct
46 Correct 38 ms 5320 KB Output is correct
47 Correct 51 ms 5348 KB Output is correct
48 Correct 52 ms 5324 KB Output is correct
49 Correct 108 ms 10196 KB Output is correct
50 Correct 73 ms 9272 KB Output is correct
51 Correct 64 ms 7564 KB Output is correct
52 Correct 82 ms 10296 KB Output is correct
53 Correct 61 ms 10336 KB Output is correct
54 Correct 65 ms 10944 KB Output is correct
55 Correct 92 ms 10228 KB Output is correct