Submission #1002904

# Submission time Handle Problem Language Result Execution time Memory
1002904 2024-06-19T21:16:46 Z leanchec Autobahn (COI21_autobahn) C++17
100 / 100
71 ms 20432 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, k, x;
	cin >> n >> k >> x;

	vector<pair<int,int>> sweep;
	sweep.push_back({0, 0});
	int qtd[300100]={}, il[300100]={}, c[300100]={};

	for(int i=0; i<n; i++){
		int l, t, r;
		cin >> l >> t >> r;
		sweep.push_back({l-1, 0});
		sweep.push_back({min(l+t-1, r), 1});
		sweep.push_back({r, 2});
	}

	sort(sweep.begin(), sweep.end());

	for(int i=1; i<sweep.size(); i++){
		if(qtd[i-1]>=k){
			c[i]=il[i-1]*(sweep[i].first-sweep[i-1].first);
		}
		if(sweep[i].second==0){
			qtd[i]=qtd[i-1]+1;
			il[i]=il[i-1];
		}
		else if(sweep[i].second==1){
			qtd[i]=qtd[i-1];
			il[i]=il[i-1]+1;
		}
		else{
			qtd[i]=qtd[i-1]-1;
			il[i]=il[i-1]-1;
		}
	}

	int pref[300100]={}, suf[300100]={};

	for(int i=1; i<sweep.size(); i++){
		pref[i]=pref[i-1]+c[i];
	}
	for(int i=sweep.size()-2; i>0; i--){
		suf[i]=suf[i+1]+c[i+1];
	}

	int resp=0;
	for(int i=1; i<sweep.size(); i++){
		if(sweep[i].first<=x)resp=max(resp, pref[i]);
		else{
			int ini=1, fim=i;
			int pos=0;
			while(ini<=fim){
				int mid=(ini+fim)/2;

				if(sweep[i].first-sweep[mid].first<=x){
					pos=mid;
					fim=mid-1;
				}
				else ini=mid+1;
			}

			int cr=pref[i]-pref[pos];
			cr+=(qtd[pos-1]>=k)*il[pos-1]*(x-(sweep[i].first-sweep[pos].first));
			resp=max(resp, cr);
		}
		if(sweep.back().first-sweep[i].first<=x)resp=max(resp, suf[i]);
		else{
			int ini=i, fim=sweep.size()-2;
			int pos=0;

			while(ini<=fim){
				int mid=(ini+fim)/2;

				if(sweep[mid].first-sweep[i].first<=x){
					pos=mid;
					ini=mid+1;
				}
				else fim=mid-1;
			}
			int cr=suf[i]-suf[pos];
			cr+=(qtd[pos]>=k)*il[pos]*(x-(sweep[pos].first-sweep[i].first));
			resp=max(cr, resp);
		}
	}

	cout << resp << '\n';
}

Compilation message

autobahn.cpp: In function 'int32_t main()':
autobahn.cpp:25:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
autobahn.cpp:45:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
autobahn.cpp:53:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i=1; i<sweep.size(); i++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12120 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 5 ms 12124 KB Output is correct
4 Correct 5 ms 12208 KB Output is correct
5 Correct 6 ms 12200 KB Output is correct
6 Correct 6 ms 12152 KB Output is correct
7 Correct 6 ms 12124 KB Output is correct
8 Correct 5 ms 12124 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12120 KB Output is correct
11 Correct 7 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12120 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 5 ms 12124 KB Output is correct
4 Correct 5 ms 12208 KB Output is correct
5 Correct 6 ms 12200 KB Output is correct
6 Correct 6 ms 12152 KB Output is correct
7 Correct 6 ms 12124 KB Output is correct
8 Correct 5 ms 12124 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12120 KB Output is correct
11 Correct 7 ms 12124 KB Output is correct
12 Correct 6 ms 12124 KB Output is correct
13 Correct 5 ms 12196 KB Output is correct
14 Correct 6 ms 12376 KB Output is correct
15 Correct 5 ms 12124 KB Output is correct
16 Correct 6 ms 12124 KB Output is correct
17 Correct 6 ms 12124 KB Output is correct
18 Correct 6 ms 12124 KB Output is correct
19 Correct 6 ms 12300 KB Output is correct
20 Correct 6 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12120 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 5 ms 12124 KB Output is correct
4 Correct 5 ms 12208 KB Output is correct
5 Correct 6 ms 12200 KB Output is correct
6 Correct 6 ms 12152 KB Output is correct
7 Correct 6 ms 12124 KB Output is correct
8 Correct 5 ms 12124 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12120 KB Output is correct
11 Correct 7 ms 12124 KB Output is correct
12 Correct 6 ms 12124 KB Output is correct
13 Correct 5 ms 12196 KB Output is correct
14 Correct 6 ms 12376 KB Output is correct
15 Correct 5 ms 12124 KB Output is correct
16 Correct 6 ms 12124 KB Output is correct
17 Correct 6 ms 12124 KB Output is correct
18 Correct 6 ms 12124 KB Output is correct
19 Correct 6 ms 12300 KB Output is correct
20 Correct 6 ms 12124 KB Output is correct
21 Correct 71 ms 20424 KB Output is correct
22 Correct 66 ms 20432 KB Output is correct
23 Correct 63 ms 20416 KB Output is correct
24 Correct 65 ms 20424 KB Output is correct
25 Correct 57 ms 20332 KB Output is correct
26 Correct 56 ms 20428 KB Output is correct
27 Correct 48 ms 20432 KB Output is correct
28 Correct 48 ms 20428 KB Output is correct
29 Correct 58 ms 20432 KB Output is correct