Submission #1094986

# Submission time Handle Problem Language Result Execution time Memory
1094986 2024-10-01T05:56:02 Z TVSown Global Warming (CEOI18_glo) C++17
100 / 100
46 ms 6112 KB
///*** Sown_Vipro ***///
/// ->GIAI BA QUOC GIA<- ///

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
#define szz(s) int(s.size())
const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
int n, x, res;
int a[N], m[N];
vector<int> L;
void solve(){
    cin >> n >> x;
    for(int i = 1; i <= n; ++i) cin >> a[i];

    L.pb(a[1]); m[1] = 1;
    for(int i = 2; i <= n; ++i){
        if(a[i] > L.back()){
            L.pb(a[i]);
            m[i] = L.size();
        }else{
            int id = lower_bound(L.begin(), L.end(), a[i]) - L.begin();
            L[id] = a[i];
            m[i] = id + 1;
        }
//        cout << m[i] << " ";
    }
    res = L.size();

    L.clear(); L.pb(a[n]);
    for(int i = n - 1; i >= 1; --i){
        int l = 0, r = L.size() - 1;
        while(l <= r){
            int mid = (l + r) / 2;
            if(L[mid] > a[i] - x){
                l = mid + 1;
            }else r = mid - 1;
        }
        res = max(res, m[i] + r + 1);

        if(a[i] < L.back()){
            L.pb(a[i]);
        }else{
            int l = 0, r = L.size() - 1;
            while(l <= r){
                int mid = (l + r) / 2;
                if(L[mid] <= a[i]){
                    r = mid - 1;
                }else l = mid + 1;
            }
            L[l] = a[i];
        }

//        for(int x : L) cout << x << " ";
//        cout << "\n";
    }
    cout << res;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    inp("in.txt");
    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:14:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
glo.cpp:72:5: note: in expansion of macro 'inp'
   72 |     inp("in.txt");
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 5468 KB Output is correct
2 Correct 38 ms 5464 KB Output is correct
3 Correct 40 ms 5432 KB Output is correct
4 Correct 37 ms 5596 KB Output is correct
5 Correct 16 ms 5344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3168 KB Output is correct
2 Correct 9 ms 3140 KB Output is correct
3 Correct 9 ms 3144 KB Output is correct
4 Correct 5 ms 3172 KB Output is correct
5 Correct 1 ms 2404 KB Output is correct
6 Correct 4 ms 3060 KB Output is correct
7 Correct 7 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3940 KB Output is correct
2 Correct 17 ms 3916 KB Output is correct
3 Correct 34 ms 5600 KB Output is correct
4 Correct 16 ms 5340 KB Output is correct
5 Correct 8 ms 3784 KB Output is correct
6 Correct 14 ms 5124 KB Output is correct
7 Correct 18 ms 5832 KB Output is correct
8 Correct 14 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 37 ms 5468 KB Output is correct
28 Correct 38 ms 5464 KB Output is correct
29 Correct 40 ms 5432 KB Output is correct
30 Correct 37 ms 5596 KB Output is correct
31 Correct 16 ms 5344 KB Output is correct
32 Correct 12 ms 3168 KB Output is correct
33 Correct 9 ms 3140 KB Output is correct
34 Correct 9 ms 3144 KB Output is correct
35 Correct 5 ms 3172 KB Output is correct
36 Correct 1 ms 2404 KB Output is correct
37 Correct 4 ms 3060 KB Output is correct
38 Correct 7 ms 3052 KB Output is correct
39 Correct 19 ms 3940 KB Output is correct
40 Correct 17 ms 3916 KB Output is correct
41 Correct 34 ms 5600 KB Output is correct
42 Correct 16 ms 5340 KB Output is correct
43 Correct 8 ms 3784 KB Output is correct
44 Correct 14 ms 5124 KB Output is correct
45 Correct 18 ms 5832 KB Output is correct
46 Correct 14 ms 3676 KB Output is correct
47 Correct 19 ms 3672 KB Output is correct
48 Correct 18 ms 3672 KB Output is correct
49 Correct 46 ms 5576 KB Output is correct
50 Correct 16 ms 5340 KB Output is correct
51 Correct 15 ms 4480 KB Output is correct
52 Correct 17 ms 5340 KB Output is correct
53 Correct 14 ms 5336 KB Output is correct
54 Correct 22 ms 6112 KB Output is correct
55 Correct 31 ms 5460 KB Output is correct