제출 #445321

#제출 시각아이디문제언어결과실행 시간메모리
445321hhhhauraGlobal Warming (CEOI18_glo)C++14
100 / 100
136 ms13196 KiB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define int long long int
#define lld long double
#define pii pair<int, int> 
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int n, x;
	vector<int> dp, cnt, a;
	void init_(int _n, int _x) {
		n = _n, x = _x;
		dp.assign(n + 1, INF);
		a.assign(n + 1, 0);
		cnt.assign(n + 1, 0);
	}
	int solve() {
		rep(i, 1, n) {
			int id = lower_bound(all(dp), a[i]) - dp.begin();
			cnt[i] = id + 1, dp[id] = a[i];
		}
		int ans = cnt[n];
		dp.assign(n + 1, INF);
		map<int, int> mp;
		rrep(i, 1, n) {
			int id = lower_bound(all(dp), -a[i]) - dp.begin();
			dp[id] = -a[i];
			auto it = mp.upper_bound(a[i]);
			if(it == mp.end() || it -> second < id + 1) {
				if(it != mp.begin()) {
					it = prev(it);
					while(true) {
						if(it -> second > id + 1) break;
						auto temp = it;
						if(it == mp.begin()) {
							mp.erase(temp);
							break;
						}
						else it = prev(it), mp.erase(temp);
					}
				}
				mp[a[i]] = id + 1; 
			}
			it = mp.upper_bound(a[i - 1] - x);
			if(it != mp.end())ans = max(ans, it -> second + cnt[i - 1]);
		}
		return ans;
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, x; cin >> n >> x;
	init_(n, x);
	rep(i, 1, n) cin >> a[i];
	cout << solve() << "\n";
	return 0;
}

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

glo.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
glo.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
glo.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
#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...