Submission #415692

# Submission time Handle Problem Language Result Execution time Memory
415692 2021-06-01T11:32:02 Z 송준혁(#7513) Road Construction (JOI21_road_construction) C++17
0 / 100
8750 ms 31376 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, K;
int X[250505], Y[250505], T[250505];
LL lim;
vector<LL> C, ans;

void upd(int k){while(k<=N+1)T[k]++,k+=k&-k;}
int f(int k){int r=0;while(k)r+=T[k],k^=k&-k;return r;}
inline int cm(LL x){return lb(C.begin(),C.end(),x)-C.begin()+1;}

struct Data{
	LL x;
	int y1, y2, v;
};
vector<Data> E;

int main(){
	scanf("%d %d", &N, &K);
	for (int i=1; i<=N; i++){
		scanf("%d %d", &X[i], &Y[i]);
		C.pb(Y[i]-X[i]);
	}
	sort(C.begin(), C.end());
	C.erase(unique(C.begin(), C.end()), C.end());
	LL lo=0, hi=4ll*MOD;
	while (lo<=hi){
		LL m=lo+hi>>1;
		int cnt=0;
		E.clear();
		memset(T, 0, sizeof T);
		for (int i=1; i<=N; i++){
			E.pb((Data){X[i]+Y[i], cm(Y[i]-X[i]), 0, 0});
			E.pb((Data){X[i]+Y[i]+m, cm(Y[i]-X[i]-m), cm(Y[i]-X[i]+m), 1});
			E.pb((Data){X[i]+Y[i]-m, cm(Y[i]-X[i]-m), cm(Y[i]-X[i]+m), -1});
		}
		sort(E.begin(), E.end(), [&](Data a, Data b){
			if (a.x != b.x) return a.x < b.x;
			return a.v < b.v;
		});
		for (Data t : E){
			if (!t.v) upd(t.y1);
			else cnt += t.v*(f(t.y2)-f(t.y1-1));
			if (cnt >= 2*K+N) break;
		}
		if (cnt >= 2*K+N) hi = m-1;
		else lo = m+1, lim = m;
	}
	printf("%lld\n", lim+1);
	return 0;
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:37:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   LL m=lo+hi>>1;
      |        ~~^~~
road_construction.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d %d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~
road_construction.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%d %d", &X[i], &Y[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8198 ms 31268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8750 ms 31376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8750 ms 31376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -