답안 #532300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532300 2022-03-02T17:00:18 Z AkiYuu Global Warming (CEOI18_glo) C++17
100 / 100
250 ms 11552 KB
/*

Problems:
Author: AkiYuu

*/

#include <bits/stdc++.h>
#define task "GROUP"
#define ll long long
#define ld long double
#define pb push_back
#define ffw(i,a,b) for (ll i = a; i <= b; i++)
#define fbw(i,b,a) for (ll i = b; i >= a; i--)
#define adj(v,adj,u) for (auto v : adj[u])
#define rep(i,a) for (auto i : a)
#define reset(a) memset(a, 0, sizeof(a))
#define sz(a) a.size()
#define all(a) a.begin(),a.end()

using namespace std;

void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
//	freopen(task".inp", "r", stdin);
//	freopen(task".out", "w", stdout);
}

const int mxn = 2e5 + 5;
typedef pair<ll, ll> ii;

int f[mxn];
int dp1[mxn], dp2[mxn];
int a[mxn];
int n , x;
int seg[4 * mxn];

vector < ii > pos;
int segID[mxn];

void upd( int id , int v ,int x, int lx, int rx){
    if ( lx == rx && lx == id ) {
        seg[x] = v;
        return;
    }
    int m = (lx + rx) / 2;
    if ( id <= m ) upd(id,v,2*x,lx,m);
    else upd(id,v,2*x+1,m+1,rx);
    seg[x] = max(seg[2*x], seg[2*x+1]);
}

int getmax(int l , int r, int x, int lx, int rx){
    if ( l > rx || lx > r || lx > rx || l > r) return -1e9;
    if ( lx >= l && rx <= r ) return seg[x];
    int m = (lx + rx) >> 1;
    return max( getmax(l,r,2*x,lx,m), getmax(l,r,2*x+1,m+1,rx) );
}


void solve(){
    cin >> n >> x;
    ffw(i,1,n) cin >> a[i];
    ffw(i,1,n) pos.pb(ii(a[i], i));
    sort(all(pos));
    ffw(i,0,n-1) segID[ pos[i].second ] = i + 1;
    int lis = 0;
    ffw(i,0,n+1) f[i] = -1e18;
    fbw(i,n,1){
        int id = lower_bound(f, f + lis, -a[i]) - f;
        f[id] = -a[i];
        dp2[i] = id + 1;
        upd(segID[i], dp2[i], 1, 1, n);
        lis = max(lis, id + 1);
    }
    lis = 0;
    ffw(i,0,n+1) f[i] = -1e18;
    ffw(i,1,n){
        int id = lower_bound(f, f + lis, a[i] - x) - f;
        f[id] = a[i] - x;
        dp1[i] = id + 1;
        lis = max(lis, id + 1);
    }
    int res = 0;
    ffw(i,1,n){
        upd(segID[i], -1, 1,1,n);
        int l = upper_bound(all(pos), ii(a[i] - x, 1000000)) - pos.begin() + 1;
        res = max(res, dp1[i] + getmax(l,n,1,1,n) );
    }
    cout << res;
}

int main(){
	fastio();
	int t = 1;
//	cin >> t;
	while (t--)
	solve();
}

Compilation message

glo.cpp: In function 'void solve()':
glo.cpp:69:25: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   69 |     ffw(i,0,n+1) f[i] = -1e18;
      |                         ^~~~~
glo.cpp:78:25: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   78 |     ffw(i,0,n+1) f[i] = -1e18;
      |                         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 416 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 9476 KB Output is correct
2 Correct 194 ms 9436 KB Output is correct
3 Correct 197 ms 9420 KB Output is correct
4 Correct 221 ms 9512 KB Output is correct
5 Correct 128 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2696 KB Output is correct
2 Correct 42 ms 2656 KB Output is correct
3 Correct 42 ms 2748 KB Output is correct
4 Correct 36 ms 2760 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 36 ms 2936 KB Output is correct
7 Correct 48 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4952 KB Output is correct
2 Correct 76 ms 4996 KB Output is correct
3 Correct 140 ms 9420 KB Output is correct
4 Correct 102 ms 9648 KB Output is correct
5 Correct 48 ms 5568 KB Output is correct
6 Correct 76 ms 10296 KB Output is correct
7 Correct 79 ms 11060 KB Output is correct
8 Correct 62 ms 6092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 416 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 236 ms 9476 KB Output is correct
28 Correct 194 ms 9436 KB Output is correct
29 Correct 197 ms 9420 KB Output is correct
30 Correct 221 ms 9512 KB Output is correct
31 Correct 128 ms 9452 KB Output is correct
32 Correct 43 ms 2696 KB Output is correct
33 Correct 42 ms 2656 KB Output is correct
34 Correct 42 ms 2748 KB Output is correct
35 Correct 36 ms 2760 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 36 ms 2936 KB Output is correct
38 Correct 48 ms 3140 KB Output is correct
39 Correct 66 ms 4952 KB Output is correct
40 Correct 76 ms 4996 KB Output is correct
41 Correct 140 ms 9420 KB Output is correct
42 Correct 102 ms 9648 KB Output is correct
43 Correct 48 ms 5568 KB Output is correct
44 Correct 76 ms 10296 KB Output is correct
45 Correct 79 ms 11060 KB Output is correct
46 Correct 62 ms 6092 KB Output is correct
47 Correct 123 ms 5940 KB Output is correct
48 Correct 91 ms 5940 KB Output is correct
49 Correct 250 ms 11552 KB Output is correct
50 Correct 107 ms 10668 KB Output is correct
51 Correct 77 ms 8632 KB Output is correct
52 Correct 165 ms 10716 KB Output is correct
53 Correct 81 ms 10856 KB Output is correct
54 Correct 87 ms 11376 KB Output is correct
55 Correct 178 ms 11384 KB Output is correct