답안 #1103052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103052 2024-10-19T16:19:15 Z kingdragon Global Warming (CEOI18_glo) C++14
100 / 100
266 ms 19648 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define iil pair<ll,ll>
#define iiil pair<ll,pair<ll,ll>>
#define oo 1e18
#define check(n) (prime[n>>6]&(1<<((n&63)>>1)))
#define set(n) prime[n>>6]|=(1<<((n&63)>>1))
using namespace std;
const int N=2e5+5;
const ll Mod=1e9+7;
const ll MOD=13141702292180207;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
 
 
int n, a[N], st[4*N], d[N], cnt[N];
int t[N], s[N], x;
set<int> m;
vector<int> b;
void up(int id,int l,int r, int u,int val)
{
    if (u>r || l>u || l>r) return;
    if (l==r)
    {
        st[id]=max(st[id],val);
        return;
    }
    int mid=(l+r)/2;
    up(id*2,l,mid,u,val);
    up(id*2+1,mid+1,r,u,val);
    st[id]=max(st[id*2],st[id*2+1]);
}
 
int get(int id,int l,int r,int u,int v)
{
    if (l>r || u>v || l>v || u>r) return 0;
    if (u<=l && r<=v) return st[id];
    int mid=(l+r)/2;
    return max(get(id*2,l,mid,u,v), get(id*2+1,mid+1,r,u,v));
}
void slove()
{
    cin >> n >> x; 
    m.insert(-500);
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        d[i]=2e9+5;
        m.insert(a[i]);
    }
    for (int i: m) b.pb(i); 
    m.clear();
    for (int i=1;i<=n;i++)
    {
        int vt=lower_bound(d+1,d+1+n,a[i])-d;
        d[vt]=a[i];
        t[i]=vt;
        // t[i]: độ dài dãy con tăng dài nhất từ 1->i
    }
    for (int i=1;i<=n;i++) d[i]=2e9+5;
    for (int i=n;i>=1;i--)
    {
        int vt=lower_bound(d+1,d+1+n,-a[i])-d;
        d[vt]=-a[i];
        s[i]=vt;
        // s[i]  độ dài dãy con tăng dài nhất từ i->n
    }
    b.pb(2e9+5);
    int ans=0;
    // giả sử từ 1->i trừ đi x đơn vị = từ i+1 -> n tăng lên x đơn vị

    for (int i=1;i<n;i++)
    {
        int vt=lower_bound(b.begin(),b.end(),a[i])-b.begin();
        up(1,1,n,vt,t[i]);
        vt=lower_bound(b.begin(),b.end(),a[i+1]+x)-b.begin();
        vt--;
        ans=max(ans,s[i+1]+get(1,1,n,1,vt));
    }
    cout << ans;
 
}
int main()
{
    // freopen("test.inp","r",stdin);
    // freopen("test.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    int T=1;
    //cin >> T;
    while(T--) slove();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 6648 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 6648 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 6648 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 2 ms 4432 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6692 KB Output is correct
23 Correct 3 ms 6480 KB Output is correct
24 Correct 2 ms 6648 KB Output is correct
25 Correct 2 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 19644 KB Output is correct
2 Correct 266 ms 19648 KB Output is correct
3 Correct 229 ms 17776 KB Output is correct
4 Correct 234 ms 19648 KB Output is correct
5 Correct 108 ms 13760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 9932 KB Output is correct
2 Correct 53 ms 9420 KB Output is correct
3 Correct 64 ms 9876 KB Output is correct
4 Correct 26 ms 8528 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 27 ms 8272 KB Output is correct
7 Correct 38 ms 9944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 13248 KB Output is correct
2 Correct 102 ms 13248 KB Output is correct
3 Correct 197 ms 19640 KB Output is correct
4 Correct 105 ms 13764 KB Output is correct
5 Correct 46 ms 12728 KB Output is correct
6 Correct 113 ms 17348 KB Output is correct
7 Correct 106 ms 18960 KB Output is correct
8 Correct 76 ms 12224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 6648 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 2 ms 4432 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6692 KB Output is correct
23 Correct 3 ms 6480 KB Output is correct
24 Correct 2 ms 6648 KB Output is correct
25 Correct 2 ms 6480 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 236 ms 19644 KB Output is correct
28 Correct 266 ms 19648 KB Output is correct
29 Correct 229 ms 17776 KB Output is correct
30 Correct 234 ms 19648 KB Output is correct
31 Correct 108 ms 13760 KB Output is correct
32 Correct 50 ms 9932 KB Output is correct
33 Correct 53 ms 9420 KB Output is correct
34 Correct 64 ms 9876 KB Output is correct
35 Correct 26 ms 8528 KB Output is correct
36 Correct 2 ms 6480 KB Output is correct
37 Correct 27 ms 8272 KB Output is correct
38 Correct 38 ms 9944 KB Output is correct
39 Correct 98 ms 13248 KB Output is correct
40 Correct 102 ms 13248 KB Output is correct
41 Correct 197 ms 19640 KB Output is correct
42 Correct 105 ms 13764 KB Output is correct
43 Correct 46 ms 12728 KB Output is correct
44 Correct 113 ms 17348 KB Output is correct
45 Correct 106 ms 18960 KB Output is correct
46 Correct 76 ms 12224 KB Output is correct
47 Correct 110 ms 13124 KB Output is correct
48 Correct 103 ms 13264 KB Output is correct
49 Correct 242 ms 19648 KB Output is correct
50 Correct 143 ms 13756 KB Output is correct
51 Correct 88 ms 13248 KB Output is correct
52 Correct 132 ms 18948 KB Output is correct
53 Correct 107 ms 18880 KB Output is correct
54 Correct 110 ms 17600 KB Output is correct
55 Correct 178 ms 19648 KB Output is correct