Submission #104953

# Submission time Handle Problem Language Result Execution time Memory
104953 2019-04-10T00:22:07 Z eriksuenderhauf Global Warming (CEOI18_glo) C++11
100 / 100
91 ms 4800 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
int a[MAXN], dp[MAXN], len[MAXN];

int main() {
    int n, x;
    ni(n), ni(x);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ni(a[i]);
        int lo = 0, hi = ans, nx = 0, nx2 = 0;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (a[dp[m]] < a[i])
                lo = m + 1, nx = m;
            else
                hi = m - 1;
        }
        lo = 0, hi = ans;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (a[dp[m]] < a[i] + x)
                lo = m + 1, nx2 = m;
            else
                hi = m - 1;
        }
        ans = max(ans, nx + 1);
        len[i] = nx2;
        if (dp[nx + 1] == 0)
            dp[nx + 1] = i;
        if (a[dp[nx + 1]] > a[i])
            dp[nx + 1] = i;
    }
    a[n + 1] = INF;
    fill(dp, dp + MAXN, n + 1);
    int ret = 0;
    ans = 0;
    for (int i = n; i > 0; i--) {
        int lo = 0, hi = ans, nx = 0;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (a[dp[m]] > a[i])
                lo = m + 1, nx = m;
            else
                hi = m - 1;
        }
        ans = max(ans, nx + 1);
        if (dp[nx + 1] == n + 1)
            dp[nx + 1] = i;
        if (a[dp[nx + 1]] < a[i])
            dp[nx + 1] = i;
        ret = max(ret, nx + 1 + len[i]);
    }
    printf("%d\n", ret);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ni(n), ni(x);
          ^
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
glo.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
glo.cpp:35:9: note: in expansion of macro 'ni'
         ni(a[i]);
         ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1196 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 2 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1196 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 2 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1196 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 2 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 4 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 4604 KB Output is correct
2 Correct 77 ms 4644 KB Output is correct
3 Correct 76 ms 4600 KB Output is correct
4 Correct 85 ms 4732 KB Output is correct
5 Correct 43 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2096 KB Output is correct
2 Correct 20 ms 2048 KB Output is correct
3 Correct 28 ms 2040 KB Output is correct
4 Correct 13 ms 1920 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 14 ms 1816 KB Output is correct
7 Correct 17 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2828 KB Output is correct
2 Correct 35 ms 2916 KB Output is correct
3 Correct 73 ms 4568 KB Output is correct
4 Correct 57 ms 3832 KB Output is correct
5 Correct 26 ms 2432 KB Output is correct
6 Correct 41 ms 3832 KB Output is correct
7 Correct 40 ms 4480 KB Output is correct
8 Correct 46 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1196 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 2 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 4 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 3 ms 1152 KB Output is correct
27 Correct 83 ms 4604 KB Output is correct
28 Correct 77 ms 4644 KB Output is correct
29 Correct 76 ms 4600 KB Output is correct
30 Correct 85 ms 4732 KB Output is correct
31 Correct 43 ms 3832 KB Output is correct
32 Correct 25 ms 2096 KB Output is correct
33 Correct 20 ms 2048 KB Output is correct
34 Correct 28 ms 2040 KB Output is correct
35 Correct 13 ms 1920 KB Output is correct
36 Correct 3 ms 1152 KB Output is correct
37 Correct 14 ms 1816 KB Output is correct
38 Correct 17 ms 2048 KB Output is correct
39 Correct 34 ms 2828 KB Output is correct
40 Correct 35 ms 2916 KB Output is correct
41 Correct 73 ms 4568 KB Output is correct
42 Correct 57 ms 3832 KB Output is correct
43 Correct 26 ms 2432 KB Output is correct
44 Correct 41 ms 3832 KB Output is correct
45 Correct 40 ms 4480 KB Output is correct
46 Correct 46 ms 2936 KB Output is correct
47 Correct 41 ms 2808 KB Output is correct
48 Correct 40 ms 2808 KB Output is correct
49 Correct 91 ms 4584 KB Output is correct
50 Correct 53 ms 3832 KB Output is correct
51 Correct 40 ms 3192 KB Output is correct
52 Correct 46 ms 3964 KB Output is correct
53 Correct 44 ms 4088 KB Output is correct
54 Correct 46 ms 4728 KB Output is correct
55 Correct 68 ms 4800 KB Output is correct