Submission #638836

#TimeUsernameProblemLanguageResultExecution timeMemory
638836ghostwriterGlobal Warming (CEOI18_glo)C++14
100 / 100
116 ms5468 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int N = 2e5 + 5;
int n, x, t[N], v[N], f[2][N], rs = 0;
void upd(int pos1, int pos2, int v) { for (int i = pos2; i <= n; i += (i & -i)) f[pos1][i] = max(f[pos1][i], v); }
int get(int pos1, int pos2) { int rs = 0; for (int i = pos2; i >= 1; i -= (i & -i)) rs = max(rs, f[pos1][i]); return rs; }
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> x;
    FOR(i, 1, n) cin >> t[i];
    FOR(i, 1, n) v[i] = t[i];
    sort(v + 1, v + 1 + n);
    FOR(i, 1, n) {
    	vi a;
    	int pos = lb(v + 1, v + 1 + n, t[i]) - v;
	    FOR(j, 0, 1) {
	    	int ans = 0;
	    	ans = max(ans, get(j, pos - 1) + 1);
	    	if (j) {
	    		int max_val = t[i] - 1 + x, pos = -1;
	    		if (max_val >= v[n]) pos = n;
	    		else pos = ub(v + 1, v + 1 + n, max_val) - v - 1;
	    		ans = max(ans, get(0, pos) + 1);
	    	}
	    	a.pb(ans);
	    	rs = max(rs, ans);
	    }
	    upd(0, pos, a[0]);
	    upd(1, pos, a[1]);
	}
    cout << rs;
    return 0;
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
glo.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 1, n) cin >> t[i];
      |     ^~~
glo.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
glo.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(i, 1, n) v[i] = t[i];
      |     ^~~
glo.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
glo.cpp:48:5: note: in expansion of macro 'FOR'
   48 |     FOR(i, 1, n) {
      |     ^~~
glo.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
glo.cpp:51:6: note: in expansion of macro 'FOR'
   51 |      FOR(j, 0, 1) {
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...