답안 #879969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879969 2023-11-28T12:14:53 Z willychan Road Construction (JOI21_road_construction) C++17
100 / 100
4510 ms 17320 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define x first
#define y second
#define int ll
struct bit{
	vector<int> arr;
	int n;
	void init(int _n){
		arr.resize(_n+1,0);
		n = _n;
	}
	void modify(int ind,int v){
		while(ind<=n){
			arr[ind]+=v;
			ind+=(ind&-ind);
		}
	}
	int query(int ind){
		int ans = 0;
		while(ind){
			ans+=arr[ind];
			ind-=(ind&-ind);
		}
		return ans;
	}
};

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;cin>>n;
	int k;cin>>k;
	pair<ll,ll> arr[n];
	for(int i=0;i<n;i++) cin>>arr[i].x>>arr[i].y;
	for(int i=0;i<n;i++){
		arr[i].x = arr[i].x+arr[i].y;
		arr[i].y = arr[i].x-2*arr[i].y;
	}
	sort(arr,arr+n);
	vector<int> d;
	for(int i=0;i<n;i++) d.push_back(arr[i].y);
	sort(d.begin(),d.end());
	d.resize(unique(d.begin(),d.end())-d.begin());
	bit B;
	B.init(d.size());
	ll l = 0;
	ll r = 1e10;
	while(r-l>1){
		ll mid = (l+r)/2;
		ll cnt = 0;
		int head = 0;
		B.modify(lower_bound(d.begin(),d.end(),arr[0].y)-d.begin()+1,1);
		for(int i=1;i<n;i++){
			while(head<i && arr[head].x<arr[i].x-mid){
				B.modify(lower_bound(d.begin(),d.end(),arr[head].y)-d.begin()+1,-1);
				head++;
			}
			int qr = upper_bound(d.begin(),d.end(),arr[i].y+mid)-d.begin();
			int ql = lower_bound(d.begin(),d.end(),arr[i].y-mid)-d.begin()+1;
			cnt+=B.query(qr)-B.query(ql-1);
			B.modify(lower_bound(d.begin(),d.end(),arr[i].y)-d.begin()+1,1);
		}
		fill(B.arr.begin(),B.arr.end(),0);
		if(cnt>=k) r = mid;
		else l = mid;
	}
	vector<ll> ans;
	set<pair<int,int> > s;
	s.insert(make_pair(arr[0].y,0));
	int head = 0;
	for(int i=1;i<n;i++)	{
		while(head<i && arr[head].x<arr[i].x-l){
			auto it = s.find(make_pair(arr[head].y,head));
			s.erase(it);
			head++;
		}
		auto it = s.upper_bound(make_pair(arr[i].y-l,-1));	
		for(;it!=s.end() && it->first<=arr[i].y+l; ++it){
			int j = it->second;
			ans.push_back(max(abs(arr[i].x-arr[j].x),abs(arr[i].y-arr[j].y)));
		}
		s.insert(make_pair(arr[i].y,i));
	}
	sort(ans.begin(),ans.end());
	assert(ans.size()<=k);
	int left = k-ans.size();
	for(auto i : ans) cout<<i<<"\n";
	for(int i=0;i<left;i++) cout<<r<<"\n";
	return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from road_construction.cpp:1:
road_construction.cpp: In function 'int main()':
road_construction.cpp:88:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   88 |  assert(ans.size()<=k);
      |         ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 40 ms 5064 KB Output is correct
3 Correct 36 ms 5084 KB Output is correct
4 Correct 33 ms 5156 KB Output is correct
5 Correct 37 ms 4044 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1838 ms 11348 KB Output is correct
2 Correct 1848 ms 11348 KB Output is correct
3 Correct 31 ms 5076 KB Output is correct
4 Correct 1808 ms 14444 KB Output is correct
5 Correct 1754 ms 14572 KB Output is correct
6 Correct 1759 ms 14412 KB Output is correct
7 Correct 1788 ms 14444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4086 ms 8408 KB Output is correct
2 Correct 4035 ms 8408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1726 ms 8404 KB Output is correct
5 Correct 1530 ms 6352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4086 ms 8408 KB Output is correct
2 Correct 4035 ms 8408 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1726 ms 8404 KB Output is correct
5 Correct 1530 ms 6352 KB Output is correct
6 Correct 4168 ms 8404 KB Output is correct
7 Correct 4045 ms 8404 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 4152 ms 13512 KB Output is correct
11 Correct 1715 ms 11464 KB Output is correct
12 Correct 1529 ms 11892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 40 ms 5064 KB Output is correct
3 Correct 36 ms 5084 KB Output is correct
4 Correct 33 ms 5156 KB Output is correct
5 Correct 37 ms 4044 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1638 ms 9740 KB Output is correct
8 Correct 1600 ms 9700 KB Output is correct
9 Correct 34 ms 5076 KB Output is correct
10 Correct 1474 ms 8876 KB Output is correct
11 Correct 1374 ms 8564 KB Output is correct
12 Correct 377 ms 6736 KB Output is correct
13 Correct 558 ms 7540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5068 KB Output is correct
2 Correct 40 ms 5064 KB Output is correct
3 Correct 36 ms 5084 KB Output is correct
4 Correct 33 ms 5156 KB Output is correct
5 Correct 37 ms 4044 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1838 ms 11348 KB Output is correct
8 Correct 1848 ms 11348 KB Output is correct
9 Correct 31 ms 5076 KB Output is correct
10 Correct 1808 ms 14444 KB Output is correct
11 Correct 1754 ms 14572 KB Output is correct
12 Correct 1759 ms 14412 KB Output is correct
13 Correct 1788 ms 14444 KB Output is correct
14 Correct 4086 ms 8408 KB Output is correct
15 Correct 4035 ms 8408 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1726 ms 8404 KB Output is correct
18 Correct 1530 ms 6352 KB Output is correct
19 Correct 4168 ms 8404 KB Output is correct
20 Correct 4045 ms 8404 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 452 KB Output is correct
23 Correct 4152 ms 13512 KB Output is correct
24 Correct 1715 ms 11464 KB Output is correct
25 Correct 1529 ms 11892 KB Output is correct
26 Correct 1638 ms 9740 KB Output is correct
27 Correct 1600 ms 9700 KB Output is correct
28 Correct 34 ms 5076 KB Output is correct
29 Correct 1474 ms 8876 KB Output is correct
30 Correct 1374 ms 8564 KB Output is correct
31 Correct 377 ms 6736 KB Output is correct
32 Correct 558 ms 7540 KB Output is correct
33 Correct 4497 ms 17240 KB Output is correct
34 Correct 4510 ms 17320 KB Output is correct
35 Correct 4030 ms 16260 KB Output is correct
36 Correct 1294 ms 13364 KB Output is correct
37 Correct 1356 ms 13328 KB Output is correct
38 Correct 1677 ms 14664 KB Output is correct