답안 #583258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583258 2022-06-25T06:57:28 Z Mr_Husanboy Global Warming (CEOI18_glo) C++14
100 / 100
671 ms 19624 KB
// Muallif: Mansuraliyev Husanboy Murotali o'g'li  >> NamPS
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long 
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define vii vector<int>
#define vll vector<ll>
// 0-9 >> 48-57;    A-Z>>65-90   and   a-z>>97-122 respectively;
const int inf=INT_MAX;
struct segtree{
	vector<int> t;
	int sz;
	void init(int n){
		t.assign(4*n+5,0); sz=n;
	}
	void upd(int x, int l, int r, int ind, int val){
		if(l==r){
			t[x]=max(t[x],val); return;
		}
		int m=(l+r)/2;
		if(ind<=m){
			upd(x*2,l,m,ind,val);
		}else upd(x*2+1,m+1,r,ind,val);
		t[x]=max(t[x*2],t[x*2+1]);
		return;
	}
	void upd(int ind, int val){
		upd(1,1,sz,ind,val);
	}
	
	void erase(int x, int l, int r, int ind){
		if(l==r){
			t[x]=0;return;
		}
		int m=(l+r)/2;
		if(ind<=m){
			erase(x*2,l,m,ind);
		}else erase(x*2+1,m+1,r,ind);
		t[x]=max(t[x*2],t[x*2+1]);
		return;
	}
	void erase(int ind){
		erase(1,1,sz,ind);
	}
	
	int get(int x, int l, int r, int lx, int rx){
		if(lx<=l&&r<=rx) return t[x];
		if(lx>r||rx<l) return 0;
		int m=(l+r)/2;
		return max(get(x*2,l,m,lx,rx),get(x*2+1,m+1,r,lx,rx));
	}
	int get(int l, int r){
		return get(1,1,sz,l,r);
	}
};
 
 
void solve(){
	int n,x; cin>>n>>x;
	vector<int> a(n+1);
	map<int,int> mp;
	for(int i=1;i<=n;i++) cin>>a[i],mp[a[i]]=0;
	int cnt=1;
	for(auto &u:mp) u.S=cnt++;
	vector<int>  l(n+1),r(n+1);
	segtree st;
	st.init(n);
	for(int i=1;i<=n;i++){
		int ind=mp[a[i]];
		l[i]=st.get(1,ind-1)+1;
		st.upd(ind,l[i]);
	}
	st.init(n);
	for(int i=n;i>0;i--){
		int ind=mp[a[i]];
		r[i]=st.get(ind+1,n)+1;
		st.upd(ind,r[i]);
	}
	vector<pair<int,int>> v(n+1);
	for(int i=1;i<=n;i++) v[i]={a[i],i};
	sort(v.begin()+1,v.end());
	vector<int> loc(n+1);
	for(int i=1;i<=n;i++) loc[v[i].S]=i;
	st.init(n);
	for(int i=1;i<=n;i++) st.upd(loc[i],r[i]);
	int ans=0;
	for(int i=1;i<=n;i++){
		st.erase(loc[i]);
		int ind=upper_bound(v.begin()+1,v.end(),make_pair(a[i]-x,inf))-v.begin();
	//	cout<<ind<<"\n";
		if(ind<=n){
			ans=max(ans,l[i]+st.get(ind,n));
		}
	}
	cout<<ans<<"\n";
}
 
int main(){
	ios;
//	int t; cin>>t; while(t--)
	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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 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 0 ms 212 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 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 630 ms 17632 KB Output is correct
2 Correct 564 ms 17496 KB Output is correct
3 Correct 530 ms 17488 KB Output is correct
4 Correct 583 ms 17424 KB Output is correct
5 Correct 212 ms 12760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 4580 KB Output is correct
2 Correct 101 ms 4556 KB Output is correct
3 Correct 89 ms 4564 KB Output is correct
4 Correct 46 ms 3388 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 47 ms 3404 KB Output is correct
7 Correct 74 ms 4548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 258 ms 8900 KB Output is correct
2 Correct 217 ms 8904 KB Output is correct
3 Correct 611 ms 17624 KB Output is correct
4 Correct 197 ms 12748 KB Output is correct
5 Correct 124 ms 8836 KB Output is correct
6 Correct 212 ms 16588 KB Output is correct
7 Correct 209 ms 16624 KB Output is correct
8 Correct 156 ms 9032 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 630 ms 17632 KB Output is correct
28 Correct 564 ms 17496 KB Output is correct
29 Correct 530 ms 17488 KB Output is correct
30 Correct 583 ms 17424 KB Output is correct
31 Correct 212 ms 12760 KB Output is correct
32 Correct 92 ms 4580 KB Output is correct
33 Correct 101 ms 4556 KB Output is correct
34 Correct 89 ms 4564 KB Output is correct
35 Correct 46 ms 3388 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 47 ms 3404 KB Output is correct
38 Correct 74 ms 4548 KB Output is correct
39 Correct 258 ms 8900 KB Output is correct
40 Correct 217 ms 8904 KB Output is correct
41 Correct 611 ms 17624 KB Output is correct
42 Correct 197 ms 12748 KB Output is correct
43 Correct 124 ms 8836 KB Output is correct
44 Correct 212 ms 16588 KB Output is correct
45 Correct 209 ms 16624 KB Output is correct
46 Correct 156 ms 9032 KB Output is correct
47 Correct 257 ms 9892 KB Output is correct
48 Correct 248 ms 9804 KB Output is correct
49 Correct 671 ms 19432 KB Output is correct
50 Correct 200 ms 13908 KB Output is correct
51 Correct 159 ms 11644 KB Output is correct
52 Correct 276 ms 18812 KB Output is correct
53 Correct 210 ms 18748 KB Output is correct
54 Correct 237 ms 19564 KB Output is correct
55 Correct 364 ms 19624 KB Output is correct