Submission #1088112

# Submission time Handle Problem Language Result Execution time Memory
1088112 2024-09-14T02:05:07 Z Bui_Quoc_Cuong Global Warming (CEOI18_glo) C++14
100 / 100
304 ms 29860 KB
// 29 . 03 . 2008 
#include <bits/stdc++.h>
using namespace std ;
//#define int long long
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<pair<int,int>> vii ;
typedef pair<int,int> ii ;
#define FOR(i,a,b) for(int i(a) ; i <= (int)b ; i++)
#define FORD(i,a,b) for(int i(a) ; i >= (int)b ; i--)
#define FORN(i,a,b) for(int i(a) ; i < (int)b ; i++)
#define all(a) a.begin() , a.end()
#define pb push_back
#define fi first
#define se second
#define BIT(mask,i) ((mask>>i)&1)
#define builtin_popcount builtin_popcountll
#define MASK(a) (1ll << a) 

template<class T> bool maxi(T &x,T y) { if (x < y) { x = y ; return true ;} return false ;}
template<class T> bool mini(T &x,T y) { if (x > y) { x = y ; return true ;} return false ;}

const int MAXN = 2e5 + 5 ;

int n , x ;
ll a[MAXN] ;
int L[MAXN] , VAL , R[MAXN] ;
unordered_map<int,int> pos ; 

void init() {
	cin >> n >> x ; 
	FOR(i,1,n) cin >> a[i] ; 
}

void Compress() {
	vi V ; 
	FOR(i,1,n) V.pb(a[i]) , V.pb(a[i] + x) ; 
	sort(all(V)) ; 
	V.resize(unique(all(V))-V.begin()) ; 
	FOR(i,0,V.size()-1) pos[V[i]] = i + 1 ; 
	VAL = V.size() ; 
}

struct SegmentTree {
	int st[8*MAXN] ; 

	void up(int pos,int val) {
		int id = 1 , l = 1 , r = VAL ; 
		while(l < r) {
			int mid = (l+r)>>1 ; 
			if(pos <= mid) id = id << 1 , r = mid ;
			else id = id << 1 | 1 , l = mid + 1 ; 
		}
		maxi(st[id],val) ; 
		while(id > 1) {
			id>>= 1 ; 
			st[id] = max(st[id<<1],st[id<<1|1]) ; 
		}
	}

	int get(int id,int l,int r,int u,int v) {
		if(l > v || r < u) return 0 ; 
		if(l >= u  && r <= v) return st[id] ; 
		int mid = (l+r)>>1 ; 
		return max(get(id<<1,l,mid,u,v),get(id<<1|1,mid+1,r,u,v)) ; 
	}

	void reset() {
		memset(st,0,sizeof st) ;  
	}
} st ; 

void solve() {
	Compress() ;
	int ans = 0 ;  
	FOR(i,1,n) {
		L[i] = st.get(1,1,VAL,1,pos[a[i]+x]-1) + 1 ; 
		int val = st.get(1,1,VAL,1,pos[a[i]]-1) + 1 ; 
		st.up(pos[a[i]],val) ;
		maxi(ans,val) ; 
		maxi(ans,L[i]) ;
	}
	st.reset() ;
	FORD(i,n,1) {
		R[i] = st.get(1,1,VAL,pos[a[i]+x]+1,VAL) + 1 ; 
		st.up(pos[a[i]+x],R[i]) ; 
	}	
	FOR(i,1,n) maxi(ans,L[i]+R[i]-1) ;
	cout << ans ; 
}

signed main() {
    #define task ""
    ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; 
    if(fopen(task".inp","r")) {
        freopen(task".inp","r",stdin) ; freopen(task".out","w",stdout) ; 
    }
    init() ;
    solve() ;
    cerr << "TIME : " << clock() * 0.001 << "s" << endl ;
    return 0 ; 
}
/* Watbor */ 

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(task".inp","r",stdin) ; freopen(task".out","w",stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:96:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(task".inp","r",stdin) ; freopen(task".out","w",stdout) ;
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6592 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6488 KB Output is correct
9 Correct 3 ms 6716 KB Output is correct
10 Correct 3 ms 6612 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6592 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6488 KB Output is correct
9 Correct 3 ms 6716 KB Output is correct
10 Correct 3 ms 6612 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6720 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6592 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6488 KB Output is correct
9 Correct 3 ms 6716 KB Output is correct
10 Correct 3 ms 6612 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6720 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 4 ms 6748 KB Output is correct
20 Correct 4 ms 6816 KB Output is correct
21 Correct 4 ms 6748 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 3 ms 6748 KB Output is correct
24 Correct 4 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 4 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 20660 KB Output is correct
2 Correct 222 ms 20568 KB Output is correct
3 Correct 226 ms 20568 KB Output is correct
4 Correct 223 ms 20612 KB Output is correct
5 Correct 103 ms 15624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 12380 KB Output is correct
2 Correct 56 ms 12408 KB Output is correct
3 Correct 56 ms 12276 KB Output is correct
4 Correct 34 ms 9980 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 24 ms 10036 KB Output is correct
7 Correct 46 ms 11152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 18256 KB Output is correct
2 Correct 126 ms 18264 KB Output is correct
3 Correct 295 ms 29856 KB Output is correct
4 Correct 131 ms 19800 KB Output is correct
5 Correct 68 ms 17620 KB Output is correct
6 Correct 110 ms 28368 KB Output is correct
7 Correct 113 ms 28972 KB Output is correct
8 Correct 107 ms 18136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6592 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6488 KB Output is correct
9 Correct 3 ms 6716 KB Output is correct
10 Correct 3 ms 6612 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6720 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 4 ms 6748 KB Output is correct
20 Correct 4 ms 6816 KB Output is correct
21 Correct 4 ms 6748 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 3 ms 6748 KB Output is correct
24 Correct 4 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 4 ms 6748 KB Output is correct
27 Correct 256 ms 20660 KB Output is correct
28 Correct 222 ms 20568 KB Output is correct
29 Correct 226 ms 20568 KB Output is correct
30 Correct 223 ms 20612 KB Output is correct
31 Correct 103 ms 15624 KB Output is correct
32 Correct 65 ms 12380 KB Output is correct
33 Correct 56 ms 12408 KB Output is correct
34 Correct 56 ms 12276 KB Output is correct
35 Correct 34 ms 9980 KB Output is correct
36 Correct 3 ms 6492 KB Output is correct
37 Correct 24 ms 10036 KB Output is correct
38 Correct 46 ms 11152 KB Output is correct
39 Correct 140 ms 18256 KB Output is correct
40 Correct 126 ms 18264 KB Output is correct
41 Correct 295 ms 29856 KB Output is correct
42 Correct 131 ms 19800 KB Output is correct
43 Correct 68 ms 17620 KB Output is correct
44 Correct 110 ms 28368 KB Output is correct
45 Correct 113 ms 28972 KB Output is correct
46 Correct 107 ms 18136 KB Output is correct
47 Correct 123 ms 18132 KB Output is correct
48 Correct 129 ms 18144 KB Output is correct
49 Correct 304 ms 29860 KB Output is correct
50 Correct 135 ms 19796 KB Output is correct
51 Correct 90 ms 15912 KB Output is correct
52 Correct 120 ms 19992 KB Output is correct
53 Correct 156 ms 29184 KB Output is correct
54 Correct 128 ms 29848 KB Output is correct
55 Correct 242 ms 24788 KB Output is correct