답안 #902266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902266 2024-01-10T07:46:24 Z Mohammadamin__Sh Global Warming (CEOI18_glo) C++17
100 / 100
378 ms 39508 KB
//In His Name
#include <bits/stdc++.h>
//#pragma GCC optimization("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
#define ll long long
//#define int ll
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
const int maxn = 2e5 + 5, MOD = 1e9 + 7 , MAX = 1e9+10 , LG = 30;
const ll INF = 1e18 + 100;

int n , x , a[maxn] , dp[maxn] , maxi[4*maxn*LG] , Lc[4*maxn*LG] , Rc[4*maxn*LG] , now = 2 , ans[maxn];

void Update(int id , int L , int R , int idx , int val){
	if(L+1 == R){
		maxi[id] = val;
		return;
	}
	int mid = (L+R) >> 1 ;
	if(idx < mid){
		if(!Lc[id]) Lc[id] = now++;
		Update(Lc[id] , L , mid , idx , val);
	}
	else{
		if(!Rc[id]) Rc[id] = now++;
		Update(Rc[id] , mid , R , idx , val);
	}
	maxi[id] = max(maxi[Lc[id]] , maxi[Rc[id]]);
}

int Get(int id , int L , int R , int l , int r){
	if(id == 0) return 0;
	if(L == l and R == r) return maxi[id];
	int mid = (L+R) >> 1 , res = 0;
	if(l < mid) res = max(res , Get(Lc[id] , L , mid , l , min(r , mid)));
	if(r > mid) res = max(res , Get(Rc[id] , mid , R , max(l , mid) , r));
	return res;
}

int32_t main(){	
	ios_base::sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	
	cin >> n >> x;
	for(int i = 1 , x ; i <= n ; i++) cin >> a[i];
	for(int i = 1 ; i <= n ; i++){
		dp[i] = Get(1 , 1 , MAX  , 1 , a[i]) + 1;
		Update(1 , 1 , MAX , a[i] , dp[i]);
	}
	for(int i = 1 ; i <= now ; i++) Lc[i] = Rc[i] = maxi[i] = 0;
	now = 2;
	for(int i = n ; i >= 1 ; i--){
		ans[i] = dp[i] + Get(1 , 1 , MAX , max(a[i] - x + 1, 1) , MAX);
		Update(1 , 1 , MAX , a[i] , Get(1 , 1 , MAX , a[i] + 1 , MAX) + 1);
		
	}
	cout << *max_element(ans+1 , ans+n+1);
	
}

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:51:18: warning: unused variable 'x' [-Wunused-variable]
   51 |  for(int i = 1 , x ; i <= n ; i++) cin >> a[i];
      |                  ^
# 결과 실행 시간 메모리 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 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4580 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 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 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4580 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4456 KB Output is correct
13 Correct 1 ms 4456 KB Output is correct
14 Correct 1 ms 4456 KB Output is correct
15 Correct 1 ms 4456 KB Output is correct
16 Correct 1 ms 4576 KB Output is correct
17 Correct 1 ms 4560 KB Output is correct
18 Correct 1 ms 4552 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 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4580 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4456 KB Output is correct
13 Correct 1 ms 4456 KB Output is correct
14 Correct 1 ms 4456 KB Output is correct
15 Correct 1 ms 4456 KB Output is correct
16 Correct 1 ms 4576 KB Output is correct
17 Correct 1 ms 4560 KB Output is correct
18 Correct 1 ms 4552 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 3 ms 4568 KB Output is correct
22 Correct 2 ms 4708 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 1 ms 4560 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 39212 KB Output is correct
2 Correct 368 ms 39116 KB Output is correct
3 Correct 362 ms 39152 KB Output is correct
4 Correct 366 ms 39488 KB Output is correct
5 Correct 198 ms 24656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 15408 KB Output is correct
2 Correct 62 ms 15520 KB Output is correct
3 Correct 72 ms 15604 KB Output is correct
4 Correct 51 ms 10500 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 45 ms 5828 KB Output is correct
7 Correct 56 ms 11696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 23736 KB Output is correct
2 Correct 148 ms 23724 KB Output is correct
3 Correct 335 ms 39252 KB Output is correct
4 Correct 185 ms 24908 KB Output is correct
5 Correct 83 ms 9520 KB Output is correct
6 Correct 153 ms 12132 KB Output is correct
7 Correct 136 ms 12876 KB Output is correct
8 Correct 107 ms 18368 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 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4448 KB Output is correct
9 Correct 1 ms 4580 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4456 KB Output is correct
13 Correct 1 ms 4456 KB Output is correct
14 Correct 1 ms 4456 KB Output is correct
15 Correct 1 ms 4456 KB Output is correct
16 Correct 1 ms 4576 KB Output is correct
17 Correct 1 ms 4560 KB Output is correct
18 Correct 1 ms 4552 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 3 ms 4568 KB Output is correct
22 Correct 2 ms 4708 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 1 ms 4560 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 363 ms 39212 KB Output is correct
28 Correct 368 ms 39116 KB Output is correct
29 Correct 362 ms 39152 KB Output is correct
30 Correct 366 ms 39488 KB Output is correct
31 Correct 198 ms 24656 KB Output is correct
32 Correct 80 ms 15408 KB Output is correct
33 Correct 62 ms 15520 KB Output is correct
34 Correct 72 ms 15604 KB Output is correct
35 Correct 51 ms 10500 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 45 ms 5828 KB Output is correct
38 Correct 56 ms 11696 KB Output is correct
39 Correct 142 ms 23736 KB Output is correct
40 Correct 148 ms 23724 KB Output is correct
41 Correct 335 ms 39252 KB Output is correct
42 Correct 185 ms 24908 KB Output is correct
43 Correct 83 ms 9520 KB Output is correct
44 Correct 153 ms 12132 KB Output is correct
45 Correct 136 ms 12876 KB Output is correct
46 Correct 107 ms 18368 KB Output is correct
47 Correct 161 ms 23656 KB Output is correct
48 Correct 191 ms 23664 KB Output is correct
49 Correct 378 ms 39508 KB Output is correct
50 Correct 156 ms 24868 KB Output is correct
51 Correct 108 ms 10120 KB Output is correct
52 Correct 193 ms 12348 KB Output is correct
53 Correct 143 ms 12556 KB Output is correct
54 Correct 182 ms 13148 KB Output is correct
55 Correct 248 ms 31576 KB Output is correct