Submission #618915

# Submission time Handle Problem Language Result Execution time Memory
618915 2022-08-02T08:20:05 Z joelau Road Construction (JOI21_road_construction) C++14
7 / 100
10000 ms 39232 KB
#include <bits/stdc++.h>
using namespace std;

long long N,K,ft[250005];
pair<long long,long long> lst[250005];
vector< tuple<long long,long long,long long,long long> > A;
vector<long long> dis;
map<long long,long long> mp;

void update (long long x, long long v) {
	x++;
	while (x <= N) ft[x] += v, x += x & -x;
}

long long query (long long x) {
	x++;
	long long ans = 0;
	while (x) ans += ft[x], x -= x & -x;
	return ans;
}

long long f(long long x) {
	if (mp.find(x) != mp.end()) return mp[x];
	A.clear();
	for (long long i = 0; i < N; ++i) {
		long long a = lower_bound(dis.begin(),dis.end(),lst[i].second) - dis.begin();
		long long b = lower_bound(dis.begin(),dis.end(),lst[i].second-x) - dis.begin();
		long long c = upper_bound(dis.begin(),dis.end(),lst[i].second+x) - dis.begin() - 1;
		A.emplace_back(lst[i].first,0,a,0);
		A.emplace_back(lst[i].first-x,-1,b,c);
		A.emplace_back(lst[i].first+x,1,b,c);
	}
	sort(A.begin(),A.end());
	for (long long i = 0; i <= N; ++i) ft[i] = 0;
	long long ans = -N;
	for (auto x: A) {
		long long a,b,c,d; tie(a,b,c,d) = x;
		if (b == 0) ans += query(c);
		if (b == -1) update(c,1), update(d+1,-1);
		if (b == 1) update(c,-1), update(d+1,1);
	}
	return mp[x] = ans/2;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> N >> K;
	for (long long i = 0; i < N; ++i) {
		long long x,y; cin >> x >> y;
		lst[i] = make_pair(x-y,x+y);
		dis.push_back(lst[i].second);
	}
	sort(dis.begin(),dis.end());
	dis.resize(unique(dis.begin(),dis.end()) - dis.begin());
	for (long long i = 1; i <= K; ++i) {
		long long low = 0, high = 4e9+5;
		while (high-low > 1) {
			long long mid = (low+high)/2;
			if (f(mid) >= i) high = mid;
			else low = mid;
		}
		cout << high << '\n';
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 10010 ms 1964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10100 ms 39088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6111 ms 39152 KB Output is correct
2 Correct 6075 ms 39068 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 6175 ms 39232 KB Output is correct
5 Correct 4772 ms 39076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6111 ms 39152 KB Output is correct
2 Correct 6075 ms 39068 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 6175 ms 39232 KB Output is correct
5 Correct 4772 ms 39076 KB Output is correct
6 Execution timed out 10040 ms 39072 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10010 ms 1964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10010 ms 1964 KB Time limit exceeded
2 Halted 0 ms 0 KB -