Submission #739685

# Submission time Handle Problem Language Result Execution time Memory
739685 2023-05-11T03:49:12 Z asdfgrace Global Warming (CEOI18_glo) C++17
100 / 100
56 ms 4556 KB
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) //x
#define A(x) DEBUG(assert(x))
#define PRINT(x) DEBUG(cerr << x)
#define PV(x) DEBUG(cerr << #x << " = " << x << '\n')
#define PV2(x) DEBUG(cerr << #x << " = " << x.first << ',' << x.second << '\n')
#define PAR(x) DEBUG(PRINT(#x << " = { "); for (auto y : x) PRINT(y << ' '); PRINT("}\n");)
#define PAR2(x) DEBUG(PRINT(#x << " = { "); for (auto [y, z] : x) PRINT(y << ',' << z << "  "); PRINT("}\n");)
typedef int64_t i64;
const int INF = 1000000007; //998244353;
 
struct S {
  int n, k;
  vector<int> a;
 
  void run() {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    
    vector<int> lis(n, INT_MAX), best(n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      int pos = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin();
      lis[pos] = a[i];
      best[i] = pos + 1;
      ans = max(ans, best[i]);
    }
    
    fill(lis.begin(), lis.end(), INT_MAX);
    for (int i = n - 1; i >= 0; --i) {
      // binary search for first element counted in LDS
      int firstcnt = lower_bound(lis.begin(), lis.end(), -a[i] + k) - lis.begin();
      ans = max(ans, best[i] + firstcnt);
      // binary search for where to add next modified element
      int pos = lower_bound(lis.begin(), lis.end(), -a[i]) - lis.begin();
      lis[pos] = -a[i];
    }
    cout << ans << '\n';
  }
};
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  auto sol = make_unique<S>();
  sol->run();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 412 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 412 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 276 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 412 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 276 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 3148 KB Output is correct
2 Correct 53 ms 3160 KB Output is correct
3 Correct 56 ms 3180 KB Output is correct
4 Correct 51 ms 3152 KB Output is correct
5 Correct 39 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1108 KB Output is correct
2 Correct 14 ms 1124 KB Output is correct
3 Correct 13 ms 1124 KB Output is correct
4 Correct 10 ms 1144 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 1108 KB Output is correct
7 Correct 11 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1876 KB Output is correct
2 Correct 23 ms 1996 KB Output is correct
3 Correct 49 ms 3364 KB Output is correct
4 Correct 41 ms 3220 KB Output is correct
5 Correct 19 ms 1992 KB Output is correct
6 Correct 33 ms 2968 KB Output is correct
7 Correct 38 ms 3072 KB Output is correct
8 Correct 20 ms 1932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 412 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 276 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 54 ms 3148 KB Output is correct
28 Correct 53 ms 3160 KB Output is correct
29 Correct 56 ms 3180 KB Output is correct
30 Correct 51 ms 3152 KB Output is correct
31 Correct 39 ms 3148 KB Output is correct
32 Correct 13 ms 1108 KB Output is correct
33 Correct 14 ms 1124 KB Output is correct
34 Correct 13 ms 1124 KB Output is correct
35 Correct 10 ms 1144 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 10 ms 1108 KB Output is correct
38 Correct 11 ms 1348 KB Output is correct
39 Correct 24 ms 1876 KB Output is correct
40 Correct 23 ms 1996 KB Output is correct
41 Correct 49 ms 3364 KB Output is correct
42 Correct 41 ms 3220 KB Output is correct
43 Correct 19 ms 1992 KB Output is correct
44 Correct 33 ms 2968 KB Output is correct
45 Correct 38 ms 3072 KB Output is correct
46 Correct 20 ms 1932 KB Output is correct
47 Correct 26 ms 2456 KB Output is correct
48 Correct 25 ms 2432 KB Output is correct
49 Correct 50 ms 4556 KB Output is correct
50 Correct 37 ms 3784 KB Output is correct
51 Correct 31 ms 2956 KB Output is correct
52 Correct 39 ms 3932 KB Output is correct
53 Correct 36 ms 3932 KB Output is correct
54 Correct 38 ms 4544 KB Output is correct
55 Correct 43 ms 4552 KB Output is correct