답안 #318040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318040 2020-10-31T10:06:09 Z Dymo Global Warming (CEOI18_glo) C++14
100 / 100
605 ms 23760 KB
#include<bits/stdc++.h>

using namespace std;


#define pb    push_back
#define eb   emplace_back
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=5e5+50;
const ll mod =998244353 ;
const ll base=3e18;
vector<ll> vt;

ll st[2][4*maxn];
ll a[maxn];

void update(ll id,ll left,ll right,ll x,ll diff,ll t )
{
    if (x>right||x<left) return ;
    if (right==left )
    {
        st[t][id]=max(st[t][id],diff);
        return ;
    }
    ll mid=(left+right)/2;
    update(id*2,left,mid, x, diff,t);
    update(id*2+1, mid+1, right, x, diff,t);
    st[t][id]=max(st[t][id*2],st[t][id*2+1]);
}
ll get(ll id,ll left,ll right,ll x,ll y,ll t)
{
    if (x>right||y<left||x> y) return 0;
    if (x<=left&&y>=right)
    {
        return st[t][id];
    }
    ll mid=(left+right)/2;
    return max(get(id*2,left,mid, x, y, t ),get(id*2+1, mid+1, right, x, y, t));

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, x ;
    cin>> n>> x ;
    vt.pb(-1e15);
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        vt.pb(a[i]);
        vt.pb(a[i]-x);
    }
    sort(vt.begin(),vt.end());
    vt.resize(unique(vt.begin(),vt.end())-vt.begin());
    ll ans=0;
    //cout <<vt.size()<<endl;
    /*for (auto to:vt)
    {
        cout <<to<<endl;
    }*/
   for (int i=1;i<=n;i++)
    {
        ll h=lower_bound(vt.begin(),vt.end(),a[i])-vt.begin();
        ll t=get(1,1,vt.size()-1,1,h-1,0)+1;
      //  cout <<1<<" "<<1<<" "<<vt.size()-1<<" "<<1<<" "<<h-1<<" "<<0<<endl;
        ll p=get(1,1,vt.size()-1,1,h-1,1)+1;
        update(1,1,vt.size()-1,h,t,0);
      //  cout <<1<<" "<<1<<" "<<vt.size()<<"
         update(1,1,vt.size()-1,h,p,1);
        ll h1=lower_bound(vt.begin(),vt.end(),a[i]-x)-vt.begin();
         update(1,1,vt.size()-1,h1,t,1);
        //cout <<t<<" "<<p<<" "<<h<<endl;
       // cout <<h<<" "<<h-1<<endl;
        ans=max(ans,t);
        ans=max(ans,p);
    }
    //update(1,1,vt.size()-1,4,2,0);
   // cout <<get(1,1,vt.size()-1,1,3,0)<<endl ;
    cout <<ans<<endl;
/*10 10
1 1 1 1 1 1 2 2 2 1
*/



}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 498 ms 13392 KB Output is correct
2 Correct 496 ms 13520 KB Output is correct
3 Correct 489 ms 13396 KB Output is correct
4 Correct 508 ms 13392 KB Output is correct
5 Correct 257 ms 9424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 5728 KB Output is correct
2 Correct 120 ms 5764 KB Output is correct
3 Correct 110 ms 5736 KB Output is correct
4 Correct 67 ms 3680 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 69 ms 3832 KB Output is correct
7 Correct 89 ms 5984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 9048 KB Output is correct
2 Correct 258 ms 9052 KB Output is correct
3 Correct 605 ms 17764 KB Output is correct
4 Correct 286 ms 12624 KB Output is correct
5 Correct 162 ms 9688 KB Output is correct
6 Correct 302 ms 18640 KB Output is correct
7 Correct 307 ms 19152 KB Output is correct
8 Correct 196 ms 10200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 498 ms 13392 KB Output is correct
28 Correct 496 ms 13520 KB Output is correct
29 Correct 489 ms 13396 KB Output is correct
30 Correct 508 ms 13392 KB Output is correct
31 Correct 257 ms 9424 KB Output is correct
32 Correct 109 ms 5728 KB Output is correct
33 Correct 120 ms 5764 KB Output is correct
34 Correct 110 ms 5736 KB Output is correct
35 Correct 67 ms 3680 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 69 ms 3832 KB Output is correct
38 Correct 89 ms 5984 KB Output is correct
39 Correct 285 ms 9048 KB Output is correct
40 Correct 258 ms 9052 KB Output is correct
41 Correct 605 ms 17764 KB Output is correct
42 Correct 286 ms 12624 KB Output is correct
43 Correct 162 ms 9688 KB Output is correct
44 Correct 302 ms 18640 KB Output is correct
45 Correct 307 ms 19152 KB Output is correct
46 Correct 196 ms 10200 KB Output is correct
47 Correct 255 ms 11992 KB Output is correct
48 Correct 254 ms 11992 KB Output is correct
49 Correct 580 ms 23760 KB Output is correct
50 Correct 291 ms 14544 KB Output is correct
51 Correct 234 ms 11856 KB Output is correct
52 Correct 317 ms 14888 KB Output is correct
53 Correct 319 ms 19024 KB Output is correct
54 Correct 329 ms 19684 KB Output is correct
55 Correct 446 ms 23632 KB Output is correct