Submission #437756

# Submission time Handle Problem Language Result Execution time Memory
437756 2021-06-27T03:14:50 Z definitelynotmee Global Warming (CEOI18_glo) C++
100 / 100
162 ms 10216 KB
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];

    vector<vector<pii>> lds;
    for(int i = n-1; i >0; i--){
        int ini = 0, fim = lds.size();
        while(ini!=fim){
            int m = (ini+fim)>>1;
            if(lds[m][lds[m].size()-1].ss <= v[i]){
                fim = m;
            } else ini = m+1;
        }
        if(ini==lds.size())
            lds.push_back({});
        lds[ini].push_back({i,v[i]});
    }
    vector<int>lis;
    int resp = 0;
    for(int i = 0; i < n; i++){
        int ini = 0, fim = lis.size();
        while(ini!=fim){
            int m = (ini+fim)>>1;
            if(lis[m] >= v[i]){
                fim = m;
            } else ini = m+1;
        }
        if(ini==lis.size())
            lis.push_back(v[i]);
        else lis[ini] = v[i];
        int i1 = -1, f1 = lds.size()-1;
        while(i1!=f1){
            int m = (i1+f1+1)>>1;
            int i2 = -1, f2 = lds[m].size()-1;
            while(i2!=f2){
                int mm = (i2+f2+1)>>1;
                if(lds[m][mm].ff > i)
                    i2 = mm;
                else f2 = mm-1;
            }
            int cur = i2 == -1 ? -INF : lds[m][i2].ss;
            if(cur > v[i]-x)
                i1 = m;
            else f1 = m-1;
        }
        resp = max(resp, ini+i1+2);
    }
    cout << resp << '\n';
    return 0;

}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if(ini==lds.size())
      |            ~~~^~~~~~~~~~~~
glo.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if(ini==lis.size())
      |            ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 5572 KB Output is correct
2 Correct 155 ms 5564 KB Output is correct
3 Correct 154 ms 5588 KB Output is correct
4 Correct 162 ms 5568 KB Output is correct
5 Correct 75 ms 8552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1700 KB Output is correct
2 Correct 33 ms 1692 KB Output is correct
3 Correct 37 ms 1676 KB Output is correct
4 Correct 19 ms 2308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 18 ms 2348 KB Output is correct
7 Correct 24 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2744 KB Output is correct
2 Correct 51 ms 2764 KB Output is correct
3 Correct 114 ms 5700 KB Output is correct
4 Correct 82 ms 8636 KB Output is correct
5 Correct 38 ms 4408 KB Output is correct
6 Correct 66 ms 9012 KB Output is correct
7 Correct 69 ms 9832 KB Output is correct
8 Correct 55 ms 2740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 155 ms 5572 KB Output is correct
28 Correct 155 ms 5564 KB Output is correct
29 Correct 154 ms 5588 KB Output is correct
30 Correct 162 ms 5568 KB Output is correct
31 Correct 75 ms 8552 KB Output is correct
32 Correct 35 ms 1700 KB Output is correct
33 Correct 33 ms 1692 KB Output is correct
34 Correct 37 ms 1676 KB Output is correct
35 Correct 19 ms 2308 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 18 ms 2348 KB Output is correct
38 Correct 24 ms 1520 KB Output is correct
39 Correct 48 ms 2744 KB Output is correct
40 Correct 51 ms 2764 KB Output is correct
41 Correct 114 ms 5700 KB Output is correct
42 Correct 82 ms 8636 KB Output is correct
43 Correct 38 ms 4408 KB Output is correct
44 Correct 66 ms 9012 KB Output is correct
45 Correct 69 ms 9832 KB Output is correct
46 Correct 55 ms 2740 KB Output is correct
47 Correct 72 ms 2764 KB Output is correct
48 Correct 72 ms 2756 KB Output is correct
49 Correct 152 ms 5608 KB Output is correct
50 Correct 74 ms 8564 KB Output is correct
51 Correct 65 ms 8176 KB Output is correct
52 Correct 78 ms 8692 KB Output is correct
53 Correct 78 ms 9552 KB Output is correct
54 Correct 69 ms 10216 KB Output is correct
55 Correct 109 ms 5176 KB Output is correct