Submission #959839

# Submission time Handle Problem Language Result Execution time Memory
959839 2024-04-09T07:49:36 Z ono_de206 Autobahn (COI21_autobahn) C++14
100 / 100
133 ms 17548 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define int long long

typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<int, int> P;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
	return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
	return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
	return in;
}

template<typename T, typename U>
	istream & operator >> (istream &in, pair<T, U> &c) {
	in >> c.first;
	in >> c.second;
	return in;
}

template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 5e5 + 10, MXLOG = 22, mod = 1e9 + 7;
const long long inf = 1e18 + 10;

void go() {
	int n, k, x;
	cin >> n >> k >> x;
	vector<pair<int, int>> A, B;
	for(int i = 1; i <= n; i++) {
		int l, t, r;
		cin >> l >> t >> r;
		A.eb(l, r);
		if(l + t <= r) B.eb(l + t, r);
	}
	vector<int> val;
	for(auto it : A) {
		val.pb(it.ff - 1);
		val.pb(it.ss);
	}
	for(auto it : B) {
		val.pb(it.ff - 1);
		val.pb(it.ss);
	}
	sort(all(val));
	val.erase(unique(all(val)), val.end());
	n = val.size();
	vector<int> pre(n), ext(n), sum(n);
	for(auto it : A) {
		it.ff = lower_bound(all(val), it.ff) - val.begin();
		it.ss = lower_bound(all(val), it.ss) - val.begin();
		pre[it.ff]++;
		if(it.ss + 1 < n) pre[it.ss + 1]--;
	}
	for(auto it : B) {
		it.ff = lower_bound(all(val), it.ff) - val.begin();
		it.ss = lower_bound(all(val), it.ss) - val.begin();
		ext[it.ff]++;
		if(it.ss + 1 < n) ext[it.ss + 1]--;
	}
	for(int i = 1; i < n; i++) {
		pre[i] += pre[i - 1];
		ext[i] += ext[i - 1];
		if(pre[i] >= k) sum[i] = ext[i];
	}
	int l = 0, now = 0, ans = 0;
	for(int i = 1; i < n; i++) {
		now += sum[i] * (val[i] - val[i - 1]);
		while(val[i] - val[l] > x) {
			l++;
			now -= sum[l] * (val[l] - val[l - 1]);
		}
		int need = x - (val[i] - val[l]);
		mxx(ans, now + need * sum[l]);
	}
	l = n - 1, now = 0;
	for(int i = n - 1; i > 0; i--) {
		now += sum[i] * (val[i] - val[i - 1]);
		while(val[l] - val[i - 1] > x) {
			now -= sum[l] * (val[l] - val[l - 1]);
			l--;
		}
		int need = x - (val[l] - val[i - 1]);
		mxx(ans, now);
		if(l + 1 < n) mxx(ans, now + need * sum[l + 1]);
	}
	cout << ans << endl;
}

signed main() {
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 133 ms 16624 KB Output is correct
22 Correct 120 ms 16616 KB Output is correct
23 Correct 111 ms 16852 KB Output is correct
24 Correct 108 ms 16408 KB Output is correct
25 Correct 110 ms 17448 KB Output is correct
26 Correct 110 ms 17012 KB Output is correct
27 Correct 107 ms 16420 KB Output is correct
28 Correct 110 ms 16692 KB Output is correct
29 Correct 120 ms 17548 KB Output is correct