답안 #383696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383696 2021-03-30T15:04:16 Z cpp219 Global Warming (CEOI18_glo) C++14
100 / 100
450 ms 18140 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e5 + 9;
const ll lim = 1e6 + 9;
const ll inf = 1e16 + 7;

ll n,x,a[N],lis[N],lds[N],ans;
vector<ll> v;

ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
}
ll bit[lim],st[4*lim];

void upd(ll p,ll val){
    for (ll i = p;i < lim;i += i & -i) bit[i] = max(bit[i],val);
}

ll Get(ll p){
    ll res = 0;
    for (ll i = p;i > 0;i -= i & -i) res = max(bit[i],res);
    return res;
}

void update(ll id,ll l,ll r,ll u,ll val){
    if (u < l||r < u) return;
    if (l == r){
        st[id] = val; return;
    }
    ll mid = (l + r)/2;
    update(id*2,l,mid,u,val); update(id*2 + 1,mid + 1,r,u,val);
    st[id] = max(st[id*2],st[id*2 + 1]);
}

ll Get_ans(ll id,ll l,ll r,ll u,ll v){
    if (v < l||r < u) return 0;
    if (u <= l&&r <= v) return st[id];
    ll mid = (l + r)/2;
    return max(Get_ans(id*2,l,mid,u,v),Get_ans(id*2 + 1,mid + 1,r,u,v));
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin>>n>>x;
    for (ll i = 1;i <= n;i++) cin>>a[i],v.push_back(a[i]),v.push_back(a[i] + x);
    compress();
    for (ll i = n;i > 0;i--){
        lds[i] = Get_ans(1,1,lim - 1,Find(a[i]) + 1,lim - 1) + 1;
        update(1,1,lim - 1,Find(a[i]),lds[i]);
    }

    for (ll i = 1;i <= n;i++){
        lis[i] = Get(Find(a[i]) - 1) + 1; //cout<<Get(Find(a[i] + x) - 1) <<" "<< lds[i]<<"\n";
        //cout<<i<<": "<<Get(Find(a[i] + x) - 1)<<" "<<lds[i]<<"\n";
        ans = max(ans,Get(Find(a[i] + x) - 1) + lds[i]); upd(Find(a[i]),lis[i]);

    }
    //return 0;
    //for (ll i = 1;i <= n;i++) cout<<lds[i]<<" "; return 0;

    cout<<ans;
}

Compilation message

glo.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
glo.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
glo.cpp: In function 'int main()':
glo.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   59 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   60 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 620 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 353 ms 13276 KB Output is correct
2 Correct 357 ms 13296 KB Output is correct
3 Correct 337 ms 13312 KB Output is correct
4 Correct 354 ms 13276 KB Output is correct
5 Correct 177 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 5096 KB Output is correct
2 Correct 81 ms 4968 KB Output is correct
3 Correct 85 ms 5096 KB Output is correct
4 Correct 46 ms 3816 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 49 ms 3816 KB Output is correct
7 Correct 67 ms 4712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 7012 KB Output is correct
2 Correct 166 ms 6884 KB Output is correct
3 Correct 450 ms 13420 KB Output is correct
4 Correct 186 ms 10844 KB Output is correct
5 Correct 107 ms 7012 KB Output is correct
6 Correct 193 ms 12640 KB Output is correct
7 Correct 190 ms 12764 KB Output is correct
8 Correct 136 ms 6884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 620 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 353 ms 13276 KB Output is correct
28 Correct 357 ms 13296 KB Output is correct
29 Correct 337 ms 13312 KB Output is correct
30 Correct 354 ms 13276 KB Output is correct
31 Correct 177 ms 10844 KB Output is correct
32 Correct 78 ms 5096 KB Output is correct
33 Correct 81 ms 4968 KB Output is correct
34 Correct 85 ms 5096 KB Output is correct
35 Correct 46 ms 3816 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 49 ms 3816 KB Output is correct
38 Correct 67 ms 4712 KB Output is correct
39 Correct 174 ms 7012 KB Output is correct
40 Correct 166 ms 6884 KB Output is correct
41 Correct 450 ms 13420 KB Output is correct
42 Correct 186 ms 10844 KB Output is correct
43 Correct 107 ms 7012 KB Output is correct
44 Correct 193 ms 12640 KB Output is correct
45 Correct 190 ms 12764 KB Output is correct
46 Correct 136 ms 6884 KB Output is correct
47 Correct 171 ms 9316 KB Output is correct
48 Correct 175 ms 9316 KB Output is correct
49 Correct 390 ms 18140 KB Output is correct
50 Correct 185 ms 13276 KB Output is correct
51 Correct 152 ms 9052 KB Output is correct
52 Correct 209 ms 13444 KB Output is correct
53 Correct 203 ms 13404 KB Output is correct
54 Correct 203 ms 13276 KB Output is correct
55 Correct 288 ms 16476 KB Output is correct