제출 #1323959

#제출 시각아이디문제언어결과실행 시간메모리
1323959ppmn_6Financial Report (JOI21_financial)C++20
100 / 100
97 ms16904 KiB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
// https://codeforces.com/blog/entry/79148
class Timer: chrono::high_resolution_clock {
    const time_point start_time;
public:
    Timer(): start_time(now()) {}
    rep elapsed_time() const {
		return chrono::duration_cast<chrono::milliseconds>(now() - start_time).count();
	}
} timer;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	set<pair<int, int>> s;
	deque<pair<int, int>> dq;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		while (s.size() && s.begin()->first < dq.front().second) {
			s.erase(s.begin());
		}
		auto it = s.lower_bound({x, 0});
		if (it == s.begin()) {
			s.insert({x, 1});
			if (next(s.begin())->second == 1) {
				s.erase(next(s.begin()));
			}
		}
		else if (it->first != x) {
			int y = prev(it)->second + 1;
			s.insert({x, prev(it)->second + 1});
			if (it->second == y) {
				s.erase(it);
			}
		}
		while (dq.size() && dq.front().first <= i - d) {
			dq.pop_front();
		}
		while (dq.size() && dq.back().second >= x) {
			dq.pop_back();
		}
		dq.push_back({i, x});
	}
	cout << prev(s.end())->second;
	
	return 0;
}
#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...