답안 #868949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868949 2023-11-02T13:26:02 Z quandlm Global Warming (CEOI18_glo) C++14
100 / 100
257 ms 34492 KB
#include <bits/stdc++.h>
#define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
#define pi pair<int,int>
#define ple tuple<int,int,int>
#define fi first
#define se second
#define ii make_pair
#define isz(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define int long long

using namespace std;

const int N = 1e6 + 10;

int n, x, pref[N], suf[N];
int cnt = 0, a[N], b[N];
vector<int> values;


int node[N * 4];
void reset() {
    FOR(i,1,4*cnt) {
        node[i]=0;
    }
}
void update (int id, int l, int r, int u, int val) {
    if (l == r) {
        node[id] = max(node[id], val);
        return;
    }
    int mid = l + r >> 1;
    if (u <= mid) update(id*2, l, mid, u, val);
    else update(id*2+1, mid+1, r, u, val);
    node[id] = max(node[id*2], node[id*2+1]);
}
int get (int id, int l, int r, int u, int v) {
    if (l > v || r < u || l > r || u > v) return 0;
    if (l >= u && r <= v) return node[id];
    int mid = l + r >> 1;
    return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}

void update (int u, int val) {
    update(1,1,cnt,u,val);
}

int get (int l, int r) {
    return get(1,1,cnt,l,r);
}

main () {
    file("dynamic");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> x;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) {
        values.push_back(a[i]);
        values.push_back(a[i]+x);
    }
    sort(ALL(values));
    values.resize(unique(ALL(values))-values.begin());
    cnt = isz(values);
    FOR(i,1,n) {
        b[i]=lower_bound(ALL(values),a[i]+x)-values.begin()+1;
        a[i]=lower_bound(ALL(values),a[i])-values.begin()+1;
    }
    REP(i,n,1) {
        suf[i] = get(a[i]+1, cnt) + 1;
        update(a[i], suf[i]);
    }
    reset();
    int res = 0;
    FOR(i,1,n) {
        pref[i] = get(1, a[i] - 1) + 1;
        res = max(res, pref[i]);
        res = max(res, get(1,b[i]-1) + suf[i]);
        update(a[i], pref[i]);
    }
    cout << res << '\n';
}

Compilation message

glo.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
glo.cpp:35:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int mid = l + r >> 1;
      |               ~~^~~
glo.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
glo.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = l + r >> 1;
      |               ~~^~~
glo.cpp: At global scope:
glo.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main () {
      | ^~~~
glo.cpp: In function 'int main()':
glo.cpp:2:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:56:5: note: in expansion of macro 'file'
   56 |     file("dynamic");
      |     ^~~~
glo.cpp:2:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:56:5: note: in expansion of macro 'file'
   56 |     file("dynamic");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8664 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8664 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8664 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 24640 KB Output is correct
2 Correct 225 ms 24404 KB Output is correct
3 Correct 221 ms 24220 KB Output is correct
4 Correct 228 ms 24768 KB Output is correct
5 Correct 118 ms 22208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 15828 KB Output is correct
2 Correct 54 ms 15736 KB Output is correct
3 Correct 54 ms 15824 KB Output is correct
4 Correct 32 ms 13008 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 32 ms 13016 KB Output is correct
7 Correct 46 ms 15832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 20676 KB Output is correct
2 Correct 118 ms 20680 KB Output is correct
3 Correct 257 ms 32400 KB Output is correct
4 Correct 130 ms 24768 KB Output is correct
5 Correct 88 ms 20684 KB Output is correct
6 Correct 158 ms 30336 KB Output is correct
7 Correct 148 ms 31124 KB Output is correct
8 Correct 97 ms 20556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8664 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 228 ms 24640 KB Output is correct
28 Correct 225 ms 24404 KB Output is correct
29 Correct 221 ms 24220 KB Output is correct
30 Correct 228 ms 24768 KB Output is correct
31 Correct 118 ms 22208 KB Output is correct
32 Correct 56 ms 15828 KB Output is correct
33 Correct 54 ms 15736 KB Output is correct
34 Correct 54 ms 15824 KB Output is correct
35 Correct 32 ms 13008 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 32 ms 13016 KB Output is correct
38 Correct 46 ms 15832 KB Output is correct
39 Correct 118 ms 20676 KB Output is correct
40 Correct 118 ms 20680 KB Output is correct
41 Correct 257 ms 32400 KB Output is correct
42 Correct 130 ms 24768 KB Output is correct
43 Correct 88 ms 20684 KB Output is correct
44 Correct 158 ms 30336 KB Output is correct
45 Correct 148 ms 31124 KB Output is correct
46 Correct 97 ms 20556 KB Output is correct
47 Correct 114 ms 21700 KB Output is correct
48 Correct 119 ms 21704 KB Output is correct
49 Correct 248 ms 34352 KB Output is correct
50 Correct 132 ms 26424 KB Output is correct
51 Correct 117 ms 25824 KB Output is correct
52 Correct 157 ms 26496 KB Output is correct
53 Correct 162 ms 33872 KB Output is correct
54 Correct 154 ms 34492 KB Output is correct
55 Correct 202 ms 32908 KB Output is correct