Submission #544471

# Submission time Handle Problem Language Result Execution time Memory
544471 2022-04-02T04:18:40 Z cig32 Global Warming (CEOI18_glo) C++17
100 / 100
79 ms 10104 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
  int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
  if(p==0) return 1 % MOD;
  long long r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
long long inv(long long b) { 
  return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) { 
  long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
  ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() { 
  for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
void solve(int tc) {
  int n, x;
  cin >> n >> x;
  int t[n+1];
  for(int i=1; i<=n; i++) cin >> t[i];
  int bucket_pref[n+1], bucket_suf[n+1];
  for(int i=0; i<=n; i++) {
    bucket_pref[i] = 2e9;
    bucket_suf[i] = 2e9;
  }
  int ans = 0;
  int pref_dp[n+1];
  for(int i=1; i<=n; i++) {
    auto it = lower_bound(bucket_pref + 1, bucket_pref + n + 1, t[i] - x);
    int d = distance(bucket_pref, it);
    bucket_pref[d] = t[i] - x;
    pref_dp[i] = d;
    ans = max(ans, d);
  }
  //cout << ans << " ";
  for(int i=n; i>=1; i--) {
    auto it = lower_bound(bucket_suf + 1, bucket_suf + n + 1, -t[i]);
    int d = distance(bucket_suf, it);
    bucket_suf[d] = -t[i];
    if(i > 1) {
      //if(i == 5) for(int j=1; j<=n; j++)cout << bucket_suf[j]<<" \n"[j==n];
      auto it2 = lower_bound(bucket_suf, bucket_suf + n + 1, -(t[i-1] - x));
      int d2 = distance(bucket_suf, it2);
      //if(i == 5) cout << "gay " << d2 << "\n";
      ans = max(ans, pref_dp[i-1] + d2 - 1);
    }
  }
  cout << ans << "\n";
}
int32_t main(){
  precomp();
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
} 
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1892 KB Output is correct
2 Correct 3 ms 1888 KB Output is correct
3 Correct 3 ms 1888 KB Output is correct
4 Correct 2 ms 1892 KB Output is correct
5 Correct 3 ms 1888 KB Output is correct
6 Correct 3 ms 1900 KB Output is correct
7 Correct 3 ms 1900 KB Output is correct
8 Correct 3 ms 1892 KB Output is correct
9 Correct 3 ms 1900 KB Output is correct
10 Correct 3 ms 1892 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1892 KB Output is correct
2 Correct 3 ms 1888 KB Output is correct
3 Correct 3 ms 1888 KB Output is correct
4 Correct 2 ms 1892 KB Output is correct
5 Correct 3 ms 1888 KB Output is correct
6 Correct 3 ms 1900 KB Output is correct
7 Correct 3 ms 1900 KB Output is correct
8 Correct 3 ms 1892 KB Output is correct
9 Correct 3 ms 1900 KB Output is correct
10 Correct 3 ms 1892 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 2 ms 1888 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 3 ms 1876 KB Output is correct
16 Correct 3 ms 1876 KB Output is correct
17 Correct 4 ms 1892 KB Output is correct
18 Correct 3 ms 1888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1892 KB Output is correct
2 Correct 3 ms 1888 KB Output is correct
3 Correct 3 ms 1888 KB Output is correct
4 Correct 2 ms 1892 KB Output is correct
5 Correct 3 ms 1888 KB Output is correct
6 Correct 3 ms 1900 KB Output is correct
7 Correct 3 ms 1900 KB Output is correct
8 Correct 3 ms 1892 KB Output is correct
9 Correct 3 ms 1900 KB Output is correct
10 Correct 3 ms 1892 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 2 ms 1888 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 3 ms 1876 KB Output is correct
16 Correct 3 ms 1876 KB Output is correct
17 Correct 4 ms 1892 KB Output is correct
18 Correct 3 ms 1888 KB Output is correct
19 Correct 3 ms 1904 KB Output is correct
20 Correct 3 ms 1876 KB Output is correct
21 Correct 3 ms 1904 KB Output is correct
22 Correct 3 ms 1904 KB Output is correct
23 Correct 3 ms 1888 KB Output is correct
24 Correct 3 ms 1888 KB Output is correct
25 Correct 3 ms 1888 KB Output is correct
26 Correct 3 ms 1888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 10068 KB Output is correct
2 Correct 71 ms 9964 KB Output is correct
3 Correct 75 ms 10100 KB Output is correct
4 Correct 79 ms 10068 KB Output is correct
5 Correct 50 ms 9212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3932 KB Output is correct
2 Correct 16 ms 3920 KB Output is correct
3 Correct 17 ms 3928 KB Output is correct
4 Correct 15 ms 3724 KB Output is correct
5 Correct 3 ms 1888 KB Output is correct
6 Correct 13 ms 3744 KB Output is correct
7 Correct 14 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5876 KB Output is correct
2 Correct 36 ms 5980 KB Output is correct
3 Correct 63 ms 10064 KB Output is correct
4 Correct 55 ms 9308 KB Output is correct
5 Correct 24 ms 5588 KB Output is correct
6 Correct 45 ms 9052 KB Output is correct
7 Correct 44 ms 9624 KB Output is correct
8 Correct 27 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1892 KB Output is correct
2 Correct 3 ms 1888 KB Output is correct
3 Correct 3 ms 1888 KB Output is correct
4 Correct 2 ms 1892 KB Output is correct
5 Correct 3 ms 1888 KB Output is correct
6 Correct 3 ms 1900 KB Output is correct
7 Correct 3 ms 1900 KB Output is correct
8 Correct 3 ms 1892 KB Output is correct
9 Correct 3 ms 1900 KB Output is correct
10 Correct 3 ms 1892 KB Output is correct
11 Correct 3 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 2 ms 1888 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 3 ms 1876 KB Output is correct
16 Correct 3 ms 1876 KB Output is correct
17 Correct 4 ms 1892 KB Output is correct
18 Correct 3 ms 1888 KB Output is correct
19 Correct 3 ms 1904 KB Output is correct
20 Correct 3 ms 1876 KB Output is correct
21 Correct 3 ms 1904 KB Output is correct
22 Correct 3 ms 1904 KB Output is correct
23 Correct 3 ms 1888 KB Output is correct
24 Correct 3 ms 1888 KB Output is correct
25 Correct 3 ms 1888 KB Output is correct
26 Correct 3 ms 1888 KB Output is correct
27 Correct 69 ms 10068 KB Output is correct
28 Correct 71 ms 9964 KB Output is correct
29 Correct 75 ms 10100 KB Output is correct
30 Correct 79 ms 10068 KB Output is correct
31 Correct 50 ms 9212 KB Output is correct
32 Correct 19 ms 3932 KB Output is correct
33 Correct 16 ms 3920 KB Output is correct
34 Correct 17 ms 3928 KB Output is correct
35 Correct 15 ms 3724 KB Output is correct
36 Correct 3 ms 1888 KB Output is correct
37 Correct 13 ms 3744 KB Output is correct
38 Correct 14 ms 3932 KB Output is correct
39 Correct 30 ms 5876 KB Output is correct
40 Correct 36 ms 5980 KB Output is correct
41 Correct 63 ms 10064 KB Output is correct
42 Correct 55 ms 9308 KB Output is correct
43 Correct 24 ms 5588 KB Output is correct
44 Correct 45 ms 9052 KB Output is correct
45 Correct 44 ms 9624 KB Output is correct
46 Correct 27 ms 5880 KB Output is correct
47 Correct 31 ms 5868 KB Output is correct
48 Correct 35 ms 5972 KB Output is correct
49 Correct 77 ms 10072 KB Output is correct
50 Correct 50 ms 9308 KB Output is correct
51 Correct 39 ms 7436 KB Output is correct
52 Correct 50 ms 9452 KB Output is correct
53 Correct 50 ms 9396 KB Output is correct
54 Correct 58 ms 10076 KB Output is correct
55 Correct 56 ms 10104 KB Output is correct