답안 #967479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967479 2024-04-22T08:14:29 Z batsukh2006 Global Warming (CEOI18_glo) C++17
100 / 100
647 ms 44884 KB
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map> 
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
 
#define MOD 1000000007
#define int long long
#define ff first
#define ss second
#define endl '\n'
const int mxN=2e5+1;
vector<int> tree(4*mxN),dp(4*mxN);
vector<priority_queue<int> > s(mxN);
int cal(int node, int L, int R, int l, int r){
    if(L>r||R<l) return 0;
    if(L>=l&&R<=r) return tree[node];
    return max(cal(node*2,L,(L+R)/2,l,r),cal(node*2+1,(L+R)/2+1,R,l,r));
}
void up(int node, int L, int R, int p, int v){
    if(L>p||R<p) return;
    if(L==R){
        tree[node]=v;
        return;
    }
    up(node*2,L,(L+R)/2,p,v);
    up(node*2+1,(L+R)/2+1,R,p,v);
    tree[node]=max(tree[node*2],tree[node*2+1]);
}
int find(int node, int L, int R, int l, int r){
    if(L>r||R<l) return 0;
    if(L>=l&&R<=r) return dp[node];
    return max(find(node*2,L,(L+R)/2,l,r),find(node*2+1,(L+R)/2+1,R,l,r));
}
void upd(int node, int L, int R, int p, int v){
    if(L>p||R<p) return;
    if(L==R){
        dp[node]=v;
        return;
    }
    upd(node*2,L,(L+R)/2,p,v);
    upd(node*2+1,(L+R)/2+1,R,p,v);
    dp[node]=max(dp[node*2],dp[node*2+1]);
}
void solve(){
	int n,d; cin>>n>>d;
	map<int,int> mp;
    vector<int> a(n+1),c(n+1),f(n+1);
    for(int i=1; i<=n; i++) cin>>a[i],f[i]=a[i],mp[a[i]];
    int k=1;
    for(auto& x: mp) x.ss=k++;
    for(int i=1; i<=n; i++) c[i]=a[i],a[i]=mp[a[i]];
    for(int i=1; i<=n; i++) s[a[i]].push(0);
    sort(c.begin(),c.end());
    for(int i=n; i>=1; i--){
    	int mx=find(1,1,n,a[i]+1,n);
    	upd(1,1,n,a[i],mx+1);
    	s[a[i]].push(mx+1);
    }
    int ans=0;
    for(int i=1; i<=n; i++){
    	s[a[i]].pop();
    	upd(1,1,n,a[i],s[a[i]].top());
    	int mx=cal(1,1,n,1,a[i]-1);
    	up(1,1,n,a[i],mx+1);
    	auto it=upper_bound(c.begin(),c.end(),f[i]-d);
    	int up=it-c.begin();
    	if(up==n+1) up=a[i]+1;
    	else up=mp[c[up]];
    	int fst=find(1,1,n,a[i]+1,n);
    	int snd=find(1,1,n,up,a[i]);
    	ans=max(ans,max(fst,snd)+mx+1);
    }
    cout<<ans;
}
signed main(){
    // freopen("248.in", "r", stdin);
    // freopen("248.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}






















# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 5 ms 19216 KB Output is correct
3 Correct 5 ms 19036 KB Output is correct
4 Correct 7 ms 19232 KB Output is correct
5 Correct 5 ms 19036 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 6 ms 19036 KB Output is correct
8 Correct 5 ms 19104 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19032 KB Output is correct
11 Correct 5 ms 19032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 5 ms 19216 KB Output is correct
3 Correct 5 ms 19036 KB Output is correct
4 Correct 7 ms 19232 KB Output is correct
5 Correct 5 ms 19036 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 6 ms 19036 KB Output is correct
8 Correct 5 ms 19104 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19032 KB Output is correct
11 Correct 5 ms 19032 KB Output is correct
12 Correct 5 ms 19036 KB Output is correct
13 Correct 5 ms 19036 KB Output is correct
14 Correct 5 ms 19052 KB Output is correct
15 Correct 5 ms 19036 KB Output is correct
16 Correct 5 ms 19064 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 5 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 5 ms 19216 KB Output is correct
3 Correct 5 ms 19036 KB Output is correct
4 Correct 7 ms 19232 KB Output is correct
5 Correct 5 ms 19036 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 6 ms 19036 KB Output is correct
8 Correct 5 ms 19104 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19032 KB Output is correct
11 Correct 5 ms 19032 KB Output is correct
12 Correct 5 ms 19036 KB Output is correct
13 Correct 5 ms 19036 KB Output is correct
14 Correct 5 ms 19052 KB Output is correct
15 Correct 5 ms 19036 KB Output is correct
16 Correct 5 ms 19064 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 5 ms 19036 KB Output is correct
19 Correct 6 ms 19184 KB Output is correct
20 Correct 6 ms 19292 KB Output is correct
21 Correct 6 ms 19292 KB Output is correct
22 Correct 7 ms 19264 KB Output is correct
23 Correct 5 ms 19292 KB Output is correct
24 Correct 5 ms 19292 KB Output is correct
25 Correct 5 ms 19292 KB Output is correct
26 Correct 6 ms 19444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 647 ms 42584 KB Output is correct
2 Correct 635 ms 44884 KB Output is correct
3 Correct 642 ms 44880 KB Output is correct
4 Correct 627 ms 44568 KB Output is correct
5 Correct 255 ms 36404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 25112 KB Output is correct
2 Correct 106 ms 25608 KB Output is correct
3 Correct 105 ms 25600 KB Output is correct
4 Correct 58 ms 23752 KB Output is correct
5 Correct 5 ms 19036 KB Output is correct
6 Correct 62 ms 23444 KB Output is correct
7 Correct 91 ms 25588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 30800 KB Output is correct
2 Correct 197 ms 30828 KB Output is correct
3 Correct 466 ms 42828 KB Output is correct
4 Correct 232 ms 35288 KB Output is correct
5 Correct 135 ms 30800 KB Output is correct
6 Correct 252 ms 41560 KB Output is correct
7 Correct 247 ms 41552 KB Output is correct
8 Correct 167 ms 30904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 5 ms 19216 KB Output is correct
3 Correct 5 ms 19036 KB Output is correct
4 Correct 7 ms 19232 KB Output is correct
5 Correct 5 ms 19036 KB Output is correct
6 Correct 6 ms 19036 KB Output is correct
7 Correct 6 ms 19036 KB Output is correct
8 Correct 5 ms 19104 KB Output is correct
9 Correct 5 ms 19036 KB Output is correct
10 Correct 5 ms 19032 KB Output is correct
11 Correct 5 ms 19032 KB Output is correct
12 Correct 5 ms 19036 KB Output is correct
13 Correct 5 ms 19036 KB Output is correct
14 Correct 5 ms 19052 KB Output is correct
15 Correct 5 ms 19036 KB Output is correct
16 Correct 5 ms 19064 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 5 ms 19036 KB Output is correct
19 Correct 6 ms 19184 KB Output is correct
20 Correct 6 ms 19292 KB Output is correct
21 Correct 6 ms 19292 KB Output is correct
22 Correct 7 ms 19264 KB Output is correct
23 Correct 5 ms 19292 KB Output is correct
24 Correct 5 ms 19292 KB Output is correct
25 Correct 5 ms 19292 KB Output is correct
26 Correct 6 ms 19444 KB Output is correct
27 Correct 647 ms 42584 KB Output is correct
28 Correct 635 ms 44884 KB Output is correct
29 Correct 642 ms 44880 KB Output is correct
30 Correct 627 ms 44568 KB Output is correct
31 Correct 255 ms 36404 KB Output is correct
32 Correct 100 ms 25112 KB Output is correct
33 Correct 106 ms 25608 KB Output is correct
34 Correct 105 ms 25600 KB Output is correct
35 Correct 58 ms 23752 KB Output is correct
36 Correct 5 ms 19036 KB Output is correct
37 Correct 62 ms 23444 KB Output is correct
38 Correct 91 ms 25588 KB Output is correct
39 Correct 203 ms 30800 KB Output is correct
40 Correct 197 ms 30828 KB Output is correct
41 Correct 466 ms 42828 KB Output is correct
42 Correct 232 ms 35288 KB Output is correct
43 Correct 135 ms 30800 KB Output is correct
44 Correct 252 ms 41560 KB Output is correct
45 Correct 247 ms 41552 KB Output is correct
46 Correct 167 ms 30904 KB Output is correct
47 Correct 237 ms 31820 KB Output is correct
48 Correct 259 ms 31828 KB Output is correct
49 Correct 629 ms 44496 KB Output is correct
50 Correct 261 ms 36492 KB Output is correct
51 Correct 195 ms 33624 KB Output is correct
52 Correct 306 ms 43992 KB Output is correct
53 Correct 280 ms 43992 KB Output is correct
54 Correct 263 ms 44628 KB Output is correct
55 Correct 417 ms 44684 KB Output is correct