답안 #1096316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096316 2024-10-04T09:27:51 Z kingdragon Global Warming (CEOI18_glo) C++14
10 / 100
431 ms 28168 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, c[N];
void build(int id,int l, int r)
{
    if (l>r) return;
    if (l==r)
    {
        st[id]=c[l][c[l].size()-1];
        return;
    }
    int mid=(l+r)/2;
    build(id*2,l,mid);
    build(id*2+1,mid+1,r);
    st[id]=max(st[id*2],st[id*2+1]);
}
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]=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;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        d[i]=2e9+5;
        m.insert(a[i]);
        c[i].pb(0);
    }
    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;
    }
    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;
        int tv=lower_bound(b.begin(),b.end(),a[i])-b.begin();
        c[tv].pb(vt); 
        m.insert(tv);
    }
    b.pb(2e9+5);
    for (int i=1;i<=n;i++) cnt[i]=c[i].size()-1;
    for (int i: m)
    {
        for (int j=0;j<c[i].size();j++)
        {
            if (j==0) continue;
            c[i][j]=max(c[i][j],c[i][j-1]);
        }
    }
    build(1,1,n);
    int ans=0;
    for (int i=1;i<=n;i++)
    {
        int vt=lower_bound(b.begin(),b.end(),a[i])-b.begin();
        cnt[vt]--;
        up(1,1,n,vt,c[vt][cnt[vt]]);
        vt=upper_bound(b.begin(),b.end(),a[i]-x)-b.begin();
        ans=max(ans,get(1,1,n,vt,n) + t[i]);
    }
    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();
}

Compilation message

glo.cpp: In function 'void slove()':
glo.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         for (int j=0;j<c[i].size();j++)
      |                      ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Incorrect 1 ms 8796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Incorrect 1 ms 8796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Incorrect 1 ms 8796 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 28104 KB Output is correct
2 Correct 419 ms 28104 KB Output is correct
3 Correct 385 ms 28100 KB Output is correct
4 Correct 431 ms 28100 KB Output is correct
5 Correct 147 ms 23660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 13272 KB Output is correct
2 Correct 67 ms 13272 KB Output is correct
3 Correct 65 ms 13272 KB Output is correct
4 Correct 40 ms 11844 KB Output is correct
5 Incorrect 2 ms 8792 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 19408 KB Output is correct
2 Correct 141 ms 19412 KB Output is correct
3 Correct 365 ms 28168 KB Output is correct
4 Correct 128 ms 23764 KB Output is correct
5 Correct 79 ms 19408 KB Output is correct
6 Correct 145 ms 27348 KB Output is correct
7 Incorrect 157 ms 27128 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Incorrect 1 ms 8796 KB Output isn't correct
8 Halted 0 ms 0 KB -