답안 #73468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73468 2018-08-28T09:56:42 Z duckmoon99 Global Warming (CEOI18_glo) C++14
100 / 100
1380 ms 26976 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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
#define ret return

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int treee[522222];
int treee1[522222];
int n;
ll x;

void upd(int h, int xx){
	for(;h <= 2*n; h+=(h&(-h))){
		treee[h]=max(treee[h],xx);
	}
}

int que(int v){
	int res = 0;
	while(v){
		res=max(res,treee[v]);
		v-=(v&(-v));
	}
	ret res;
}

void upd1(int h, int xx){
	for(;h <= 2*n; h+=(h&(-h))){
		treee1[h]=max(treee1[h],xx);
	}
}

int que1(int v){
	//cout << v << endl;
	int res = 0;
	while(v){
		res=max(res,treee1[v]);
		v-=(v&(-v));
	}
	ret res;
}

vi b;
map<int,int> id;
int a[222222],p[222222], s[222222];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> x;
    for(int i = 0; i < n; i++){
		cin >> a[i];
		b.pb(a[i]);
		b.pb(a[i]+x-1);
	}
	sort(b.begin(),b.end());
	for(int i = 0; i < 2*n; i++){
		id[b[i]]=i+1;
	}
	for(int i = 0; i < n; i++){
		p[i]=que(id[a[i]]-1)+1;
		upd(id[a[i]],p[i]);
	}
	b.clear();
	for(int i = 0; i < n; i++){
		b.pb(-id[a[i]]+2*n+1);
	}
	reverse(b.begin(),b.end());
	for(int i = 0; i < n; i++){
		//cout << b[i] << " ";
		s[n-i-1]=que1(b[i]-1)+1;
		upd1(b[i],s[n-i-1]);
	}
	int ans = p[n-1];
	memset(treee,0,sizeof(treee));
	for(int i = 0; i < n; i++){
		ans=max(que(id[a[i]+x-1])+s[i],ans);
		upd(id[a[i]],p[i]);
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 5 ms 2424 KB Output is correct
3 Correct 5 ms 2568 KB Output is correct
4 Correct 6 ms 2568 KB Output is correct
5 Correct 4 ms 2568 KB Output is correct
6 Correct 4 ms 2568 KB Output is correct
7 Correct 4 ms 2568 KB Output is correct
8 Correct 4 ms 2568 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 5 ms 2424 KB Output is correct
3 Correct 5 ms 2568 KB Output is correct
4 Correct 6 ms 2568 KB Output is correct
5 Correct 4 ms 2568 KB Output is correct
6 Correct 4 ms 2568 KB Output is correct
7 Correct 4 ms 2568 KB Output is correct
8 Correct 4 ms 2568 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2644 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 6 ms 2648 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2648 KB Output is correct
17 Correct 4 ms 2648 KB Output is correct
18 Correct 5 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 5 ms 2424 KB Output is correct
3 Correct 5 ms 2568 KB Output is correct
4 Correct 6 ms 2568 KB Output is correct
5 Correct 4 ms 2568 KB Output is correct
6 Correct 4 ms 2568 KB Output is correct
7 Correct 4 ms 2568 KB Output is correct
8 Correct 4 ms 2568 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2644 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 6 ms 2648 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2648 KB Output is correct
17 Correct 4 ms 2648 KB Output is correct
18 Correct 5 ms 2648 KB Output is correct
19 Correct 6 ms 2772 KB Output is correct
20 Correct 5 ms 2772 KB Output is correct
21 Correct 5 ms 2772 KB Output is correct
22 Correct 5 ms 2772 KB Output is correct
23 Correct 7 ms 2772 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 6 ms 2772 KB Output is correct
26 Correct 6 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1246 ms 26968 KB Output is correct
2 Correct 1322 ms 26976 KB Output is correct
3 Correct 1339 ms 26976 KB Output is correct
4 Correct 1380 ms 26976 KB Output is correct
5 Correct 348 ms 26976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 26976 KB Output is correct
2 Correct 194 ms 26976 KB Output is correct
3 Correct 223 ms 26976 KB Output is correct
4 Correct 71 ms 26976 KB Output is correct
5 Correct 5 ms 26976 KB Output is correct
6 Correct 55 ms 26976 KB Output is correct
7 Correct 128 ms 26976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 26976 KB Output is correct
2 Correct 622 ms 26976 KB Output is correct
3 Correct 1088 ms 26976 KB Output is correct
4 Correct 310 ms 26976 KB Output is correct
5 Correct 198 ms 26976 KB Output is correct
6 Correct 366 ms 26976 KB Output is correct
7 Correct 382 ms 26976 KB Output is correct
8 Correct 274 ms 26976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 5 ms 2424 KB Output is correct
3 Correct 5 ms 2568 KB Output is correct
4 Correct 6 ms 2568 KB Output is correct
5 Correct 4 ms 2568 KB Output is correct
6 Correct 4 ms 2568 KB Output is correct
7 Correct 4 ms 2568 KB Output is correct
8 Correct 4 ms 2568 KB Output is correct
9 Correct 5 ms 2644 KB Output is correct
10 Correct 5 ms 2644 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2644 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 6 ms 2648 KB Output is correct
15 Correct 4 ms 2648 KB Output is correct
16 Correct 4 ms 2648 KB Output is correct
17 Correct 4 ms 2648 KB Output is correct
18 Correct 5 ms 2648 KB Output is correct
19 Correct 6 ms 2772 KB Output is correct
20 Correct 5 ms 2772 KB Output is correct
21 Correct 5 ms 2772 KB Output is correct
22 Correct 5 ms 2772 KB Output is correct
23 Correct 7 ms 2772 KB Output is correct
24 Correct 5 ms 2772 KB Output is correct
25 Correct 6 ms 2772 KB Output is correct
26 Correct 6 ms 2772 KB Output is correct
27 Correct 1246 ms 26968 KB Output is correct
28 Correct 1322 ms 26976 KB Output is correct
29 Correct 1339 ms 26976 KB Output is correct
30 Correct 1380 ms 26976 KB Output is correct
31 Correct 348 ms 26976 KB Output is correct
32 Correct 226 ms 26976 KB Output is correct
33 Correct 194 ms 26976 KB Output is correct
34 Correct 223 ms 26976 KB Output is correct
35 Correct 71 ms 26976 KB Output is correct
36 Correct 5 ms 26976 KB Output is correct
37 Correct 55 ms 26976 KB Output is correct
38 Correct 128 ms 26976 KB Output is correct
39 Correct 618 ms 26976 KB Output is correct
40 Correct 622 ms 26976 KB Output is correct
41 Correct 1088 ms 26976 KB Output is correct
42 Correct 310 ms 26976 KB Output is correct
43 Correct 198 ms 26976 KB Output is correct
44 Correct 366 ms 26976 KB Output is correct
45 Correct 382 ms 26976 KB Output is correct
46 Correct 274 ms 26976 KB Output is correct
47 Correct 502 ms 26976 KB Output is correct
48 Correct 450 ms 26976 KB Output is correct
49 Correct 1262 ms 26976 KB Output is correct
50 Correct 286 ms 26976 KB Output is correct
51 Correct 254 ms 26976 KB Output is correct
52 Correct 389 ms 26976 KB Output is correct
53 Correct 395 ms 26976 KB Output is correct
54 Correct 411 ms 26976 KB Output is correct
55 Correct 743 ms 26976 KB Output is correct