제출 #981457

#제출 시각아이디문제언어결과실행 시간메모리
981457kh0iGlobal Warming (CEOI18_glo)C++17
0 / 100
203 ms11912 KiB
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll> (l, r)(rng); } struct ST{ int n; vector<ll> st; void init(int _n){ n = _n; st.clear(); st.resize(4 * n + 6, 0); } void _update(int id, int l, int r, int pos, int val){ if(l == r){ st[id] = val; return; } int mid = (l + r) >> 1; if(pos <= mid) _update(id << 1, l, mid, pos, val); else _update(id << 1 | 1, mid + 1, r, pos, val); st[id] = max(st[id << 1], st[id << 1 | 1]); } int _get(int id, int l, int r, int tl, int tr){ if(l > tr or tl > r) return 0; if(tl <= l and r <= tr) return st[id]; int mid = (l + r) >> 1; return max(_get(id << 1, l, mid, tl, tr), _get(id << 1 | 1, mid + 1, r, tl, tr)); } void update(int pos, int val){ _update(1, 1, n, pos, val); } int get(int l, int r) { return _get(1, 1, n, l, r); } } st; const int N = 2e5 + 3; int n, x, t[N], tc[N], f[N]; vector<int> xx; void solve(){ cin >> n >> x; for(int i = 1; i <= n; ++i){ cin >> t[i]; xx.push_back(t[i]); } xx.push_back(0); sort(all(xx)); xx.resize(unique(all(xx)) - xx.begin()); st.init(N); for(int i = n; i >= 1; --i){ tc[i] = lower_bound(all(xx), t[i]) - xx.begin(); f[i] = st.get(tc[i] + 1, N) + 1; st.update(tc[i], f[i]); } int res = *max_element(f + 1, f + n + 1); st.init(N); for(int i = 1; i <= n; ++i){ int bound = upper_bound(all(xx), t[i] + x - 1) - xx.begin() - 1; res = max(res, st.get(1, bound) + f[i]); st.update(tc[i], st.get(tc[i] + 1, N) + 1); } cout << res; } int32_t main() { cin.tie(nullptr)->sync_with_stdio(0); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; // cin >> test; for(int i = 1; i <= test; ++i){ // cout << "Case #" << i << ": "; solve(); } #ifdef LOCAL cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; #endif return 0; }

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int32_t main()':
glo.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...