Submission #144679

# Submission time Handle Problem Language Result Execution time Memory
144679 2019-08-17T13:25:06 Z nhamtan Global Warming (CEOI18_glo) C++14
100 / 100
1525 ms 59592 KB
#include<bits/stdc++.h>
using namespace std;
 
#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >
 
#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()
 
#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)
 
#define ll long long
#define oo 2e9
#define int long long
 
const int N = 2e5 + 5;
int n , val , res;
int a[3 * N] , f[N] , b[3 * N] , dp[N];
int st[12 * N];
unordered_map < int , int > m;
 
void up(int id , int l , int r , int i , int val)
{
    if(l > i || r < i)
        return;
    if(l == r)
    {
        st[id] = max(st[id] , val);
        return;
    }
    int mid = (l + r) / 2;
    up(id * 2 , l , mid , i , val);
    up(id * 2 + 1 , mid + 1 , r , i , val);
    st[id] = max(st[id * 2] , st[id * 2 + 1]);
}
 
int get(int id , int l , int r , int u , int v)
{
    if(l > v || r < u)
        return 0;
    else if(l >= u && r <= v)
        return st[id];
    int mid = (l + r) / 2;
    return max(get(id * 2 , l , mid , u , v) , get(id * 2 + 1 , mid + 1 , r , u , v));
}
 
main()
{
    //freopen("GLO.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> val;
    FOR(i , 1 , n)
    {
        cin >> a[i];
        b[i] = a[i];
        a[i + n] = b[i + n] = a[i] + val;
        b[i + 2 * n] = a[i + 2 * n] = a[i] - val;
    }
 
 
    sort(b + 1 , b + 1 + 3 * n);
    b[0] = -oo;
    int r = 0;
    FOR(i , 1 , 3 * n)
    {
        if(b[i] != b[i - 1])
            m[b[i]] = ++r;
        else
            m[b[i]] = r;
    }
 
    FORD(i , n , 1)
    {
        f[i] = get(1 , 1 , r , m[a[i]] + 1 , r) + 1;
        up(1 , 1 , r , m[a[i]] , f[i]);
    }

    memset(st , 0 , sizeof(st));
    FOR(i , 1 , n)
    {
        dp[i] = get(1 , 1 , r , 1 , m[a[i]] - 1) + 1;
        up(1 , 1 , r , m[a[i]] , dp[i]);
    }
 
    memset(st , 0 , sizeof(st));
    FOR(i , 1 , n)
    {
        res = max(res , f[i] + get(1 , 1 , r , 1 , m[a[i + n]] - 1));
        up(1 , 1 , r , m[a[i]] , dp[i]);
    }
    memset(st , 0 , sizeof(st));
    FORD(i , n , 1)
    {
        res = max(res , dp[i] + get(1 , 1 , r , m[a[i + 2 * n]] + 1 , r));
        up(1 , 1 , r , m[a[i]] , f[i]);
    }
     /// hết phần dương.
 
 
    cout << res;
}

Compilation message

glo.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 23 ms 19192 KB Output is correct
3 Correct 24 ms 19064 KB Output is correct
4 Correct 22 ms 19192 KB Output is correct
5 Correct 22 ms 19192 KB Output is correct
6 Correct 22 ms 19192 KB Output is correct
7 Correct 24 ms 19192 KB Output is correct
8 Correct 23 ms 19192 KB Output is correct
9 Correct 24 ms 19192 KB Output is correct
10 Correct 22 ms 19192 KB Output is correct
11 Correct 22 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 23 ms 19192 KB Output is correct
3 Correct 24 ms 19064 KB Output is correct
4 Correct 22 ms 19192 KB Output is correct
5 Correct 22 ms 19192 KB Output is correct
6 Correct 22 ms 19192 KB Output is correct
7 Correct 24 ms 19192 KB Output is correct
8 Correct 23 ms 19192 KB Output is correct
9 Correct 24 ms 19192 KB Output is correct
10 Correct 22 ms 19192 KB Output is correct
11 Correct 22 ms 19192 KB Output is correct
12 Correct 23 ms 19192 KB Output is correct
13 Correct 24 ms 19064 KB Output is correct
14 Correct 22 ms 19192 KB Output is correct
15 Correct 24 ms 19352 KB Output is correct
16 Correct 22 ms 19192 KB Output is correct
17 Correct 23 ms 19192 KB Output is correct
18 Correct 29 ms 19320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 23 ms 19192 KB Output is correct
3 Correct 24 ms 19064 KB Output is correct
4 Correct 22 ms 19192 KB Output is correct
5 Correct 22 ms 19192 KB Output is correct
6 Correct 22 ms 19192 KB Output is correct
7 Correct 24 ms 19192 KB Output is correct
8 Correct 23 ms 19192 KB Output is correct
9 Correct 24 ms 19192 KB Output is correct
10 Correct 22 ms 19192 KB Output is correct
11 Correct 22 ms 19192 KB Output is correct
12 Correct 23 ms 19192 KB Output is correct
13 Correct 24 ms 19064 KB Output is correct
14 Correct 22 ms 19192 KB Output is correct
15 Correct 24 ms 19352 KB Output is correct
16 Correct 22 ms 19192 KB Output is correct
17 Correct 23 ms 19192 KB Output is correct
18 Correct 29 ms 19320 KB Output is correct
19 Correct 25 ms 19320 KB Output is correct
20 Correct 26 ms 19320 KB Output is correct
21 Correct 26 ms 19376 KB Output is correct
22 Correct 26 ms 19324 KB Output is correct
23 Correct 32 ms 19320 KB Output is correct
24 Correct 24 ms 19320 KB Output is correct
25 Correct 24 ms 19320 KB Output is correct
26 Correct 25 ms 19320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1016 ms 41600 KB Output is correct
2 Correct 1002 ms 41568 KB Output is correct
3 Correct 1010 ms 41712 KB Output is correct
4 Correct 1083 ms 41660 KB Output is correct
5 Correct 509 ms 36872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 29112 KB Output is correct
2 Correct 298 ms 29324 KB Output is correct
3 Correct 311 ms 29356 KB Output is correct
4 Correct 167 ms 25864 KB Output is correct
5 Correct 23 ms 19064 KB Output is correct
6 Correct 112 ms 24616 KB Output is correct
7 Correct 224 ms 28092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 670 ms 39288 KB Output is correct
2 Correct 657 ms 39300 KB Output is correct
3 Correct 1510 ms 59592 KB Output is correct
4 Correct 703 ms 45828 KB Output is correct
5 Correct 266 ms 38792 KB Output is correct
6 Correct 527 ms 57228 KB Output is correct
7 Correct 518 ms 57964 KB Output is correct
8 Correct 560 ms 39396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 23 ms 19192 KB Output is correct
3 Correct 24 ms 19064 KB Output is correct
4 Correct 22 ms 19192 KB Output is correct
5 Correct 22 ms 19192 KB Output is correct
6 Correct 22 ms 19192 KB Output is correct
7 Correct 24 ms 19192 KB Output is correct
8 Correct 23 ms 19192 KB Output is correct
9 Correct 24 ms 19192 KB Output is correct
10 Correct 22 ms 19192 KB Output is correct
11 Correct 22 ms 19192 KB Output is correct
12 Correct 23 ms 19192 KB Output is correct
13 Correct 24 ms 19064 KB Output is correct
14 Correct 22 ms 19192 KB Output is correct
15 Correct 24 ms 19352 KB Output is correct
16 Correct 22 ms 19192 KB Output is correct
17 Correct 23 ms 19192 KB Output is correct
18 Correct 29 ms 19320 KB Output is correct
19 Correct 25 ms 19320 KB Output is correct
20 Correct 26 ms 19320 KB Output is correct
21 Correct 26 ms 19376 KB Output is correct
22 Correct 26 ms 19324 KB Output is correct
23 Correct 32 ms 19320 KB Output is correct
24 Correct 24 ms 19320 KB Output is correct
25 Correct 24 ms 19320 KB Output is correct
26 Correct 25 ms 19320 KB Output is correct
27 Correct 1016 ms 41600 KB Output is correct
28 Correct 1002 ms 41568 KB Output is correct
29 Correct 1010 ms 41712 KB Output is correct
30 Correct 1083 ms 41660 KB Output is correct
31 Correct 509 ms 36872 KB Output is correct
32 Correct 292 ms 29112 KB Output is correct
33 Correct 298 ms 29324 KB Output is correct
34 Correct 311 ms 29356 KB Output is correct
35 Correct 167 ms 25864 KB Output is correct
36 Correct 23 ms 19064 KB Output is correct
37 Correct 112 ms 24616 KB Output is correct
38 Correct 224 ms 28092 KB Output is correct
39 Correct 670 ms 39288 KB Output is correct
40 Correct 657 ms 39300 KB Output is correct
41 Correct 1510 ms 59592 KB Output is correct
42 Correct 703 ms 45828 KB Output is correct
43 Correct 266 ms 38792 KB Output is correct
44 Correct 527 ms 57228 KB Output is correct
45 Correct 518 ms 57964 KB Output is correct
46 Correct 560 ms 39396 KB Output is correct
47 Correct 684 ms 39332 KB Output is correct
48 Correct 675 ms 39432 KB Output is correct
49 Correct 1525 ms 59580 KB Output is correct
50 Correct 770 ms 45704 KB Output is correct
51 Correct 331 ms 37424 KB Output is correct
52 Correct 438 ms 41044 KB Output is correct
53 Correct 563 ms 58852 KB Output is correct
54 Correct 539 ms 59500 KB Output is correct
55 Correct 1130 ms 55528 KB Output is correct