답안 #440204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440204 2021-07-01T17:57:12 Z cheetose Road Construction (JOI21_road_construction) C++17
100 / 100
5710 ms 36104 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int x[250005],y[250005];
Vi v[250005];
Vll vx,vy;
int N,M;
int n,k;

int tree[250005];
void upd(int i, int k){
	i++;
	while (i <= n){
		tree[i] += k;
		i += (i&-i);
	}
}
int sum(int i){
	int c = 0;
	i++;
	while (i > 0){
		c += tree[i];
		i -= (i&-i);
	}
	return c;
}
bool ok(ll m){
	MEM0(tree);
	ll res=0;
	int t=0;
	fup(i,0,N-1,1){
		ll x=vx[i];
		while(vx[t]<x-m){
			for(int j:v[t])upd(j,-1);
			t++;
		}
		for(int j:v[i]){
			ll y=vy[j];
			res+=sum(upper_bound(ALL(vy),y+m)-vy.begin()-1)-sum(lower_bound(ALL(vy),y-m)-vy.begin()-1);
			upd(j,1);
		}
	}
	return res>=k;
}
Vll ans;
list<int> lst[250005];
set<int> S;
void go(ll m){
	int t=0;
	fup(i,0,N-1,1){
		ll x=vx[i];
		while(vx[t]<x-m){
			for(int j:v[t]){
				lst[j].pop_front();
				if(lst[j].empty())S.erase(j);
			}
			t++;
		}
		for(int j:v[i]){
			ll y=vy[j];
			int L=lower_bound(ALL(vy),y-m)-vy.begin(),R=upper_bound(ALL(vy),y+m)-vy.begin()-1;
			auto it=S.lower_bound(L);
			while(it!=S.end() && *it<=R){
				int jj=*it;
				for(int ii:lst[jj]){
					ll DX=abs(vx[ii]-vx[i]),DY=abs(vy[jj]-vy[j]);
					ans.pb(max(DX,DY));
				}
				it++;
			}
			lst[j].push_back(i);
			if(lst[j].size()==1)S.insert(j);
		}
	}
}
int main(){
	scanf("%d%d",&n,&k);
	Vi vv;
	fup(i,0,n-1,1){
		int a,b;
		scanf("%d%d",&a,&b);
		x[i]=a+b,y[i]=a-b;
		vx.pb(x[i]),vy.pb(y[i]);
	}
	COMPRESS(vx);COMPRESS(vy);
	fup(i,0,n-1,1){
		v[lower_bound(ALL(vx),x[i])-vx.begin()].pb(lower_bound(ALL(vy),y[i])-vy.begin());
	}
	N=vx.size(),M=vy.size();
	ll l=1,r=4e9;
	while(l<=r){
		ll m=l+r>>1;
		if(ok(m))r=m-1;
		else l=m+1;
	}
	go(l-1);
	sort(ALL(ans));
	for(ll x:ans)printf("%lld\n",x);
	int c=k-(int)ans.size();
	while(c--)printf("%lld\n",l);
}

Compilation message

road_construction.cpp: In function 'bool ok(ll)':
road_construction.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
road_construction.cpp:70:2: note: in expansion of macro 'fup'
   70 |  fup(i,0,N-1,1){
      |  ^~~
road_construction.cpp: In function 'void go(ll)':
road_construction.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
road_construction.cpp:89:2: note: in expansion of macro 'fup'
   89 |  fup(i,0,N-1,1){
      |  ^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
road_construction.cpp:118:2: note: in expansion of macro 'fup'
  118 |  fup(i,0,n-1,1){
      |  ^~~
road_construction.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
road_construction.cpp:125:2: note: in expansion of macro 'fup'
  125 |  fup(i,0,n-1,1){
      |  ^~~
road_construction.cpp:131:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  131 |   ll m=l+r>>1;
      |        ~^~
road_construction.cpp:116:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
road_construction.cpp:120:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |   scanf("%d%d",&a,&b);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 17840 KB Output is correct
2 Correct 71 ms 17724 KB Output is correct
3 Correct 79 ms 17712 KB Output is correct
4 Correct 69 ms 17840 KB Output is correct
5 Correct 66 ms 16560 KB Output is correct
6 Correct 12 ms 13004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2580 ms 30016 KB Output is correct
2 Correct 2590 ms 30024 KB Output is correct
3 Correct 66 ms 17596 KB Output is correct
4 Correct 2578 ms 29816 KB Output is correct
5 Correct 2681 ms 30036 KB Output is correct
6 Correct 2736 ms 30048 KB Output is correct
7 Correct 2513 ms 29780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5078 ms 26724 KB Output is correct
2 Correct 4914 ms 26760 KB Output is correct
3 Correct 9 ms 13004 KB Output is correct
4 Correct 2615 ms 29664 KB Output is correct
5 Correct 1659 ms 25808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5078 ms 26724 KB Output is correct
2 Correct 4914 ms 26760 KB Output is correct
3 Correct 9 ms 13004 KB Output is correct
4 Correct 2615 ms 29664 KB Output is correct
5 Correct 1659 ms 25808 KB Output is correct
6 Correct 4842 ms 31784 KB Output is correct
7 Correct 4909 ms 31784 KB Output is correct
8 Correct 9 ms 13004 KB Output is correct
9 Correct 9 ms 13004 KB Output is correct
10 Correct 4791 ms 31168 KB Output is correct
11 Correct 2526 ms 29636 KB Output is correct
12 Correct 1687 ms 25808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 17840 KB Output is correct
2 Correct 71 ms 17724 KB Output is correct
3 Correct 79 ms 17712 KB Output is correct
4 Correct 69 ms 17840 KB Output is correct
5 Correct 66 ms 16560 KB Output is correct
6 Correct 12 ms 13004 KB Output is correct
7 Correct 1824 ms 24580 KB Output is correct
8 Correct 1742 ms 24680 KB Output is correct
9 Correct 66 ms 17840 KB Output is correct
10 Correct 1542 ms 23564 KB Output is correct
11 Correct 1412 ms 23152 KB Output is correct
12 Correct 601 ms 20056 KB Output is correct
13 Correct 576 ms 20644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 17840 KB Output is correct
2 Correct 71 ms 17724 KB Output is correct
3 Correct 79 ms 17712 KB Output is correct
4 Correct 69 ms 17840 KB Output is correct
5 Correct 66 ms 16560 KB Output is correct
6 Correct 12 ms 13004 KB Output is correct
7 Correct 2580 ms 30016 KB Output is correct
8 Correct 2590 ms 30024 KB Output is correct
9 Correct 66 ms 17596 KB Output is correct
10 Correct 2578 ms 29816 KB Output is correct
11 Correct 2681 ms 30036 KB Output is correct
12 Correct 2736 ms 30048 KB Output is correct
13 Correct 2513 ms 29780 KB Output is correct
14 Correct 5078 ms 26724 KB Output is correct
15 Correct 4914 ms 26760 KB Output is correct
16 Correct 9 ms 13004 KB Output is correct
17 Correct 2615 ms 29664 KB Output is correct
18 Correct 1659 ms 25808 KB Output is correct
19 Correct 4842 ms 31784 KB Output is correct
20 Correct 4909 ms 31784 KB Output is correct
21 Correct 9 ms 13004 KB Output is correct
22 Correct 9 ms 13004 KB Output is correct
23 Correct 4791 ms 31168 KB Output is correct
24 Correct 2526 ms 29636 KB Output is correct
25 Correct 1687 ms 25808 KB Output is correct
26 Correct 1824 ms 24580 KB Output is correct
27 Correct 1742 ms 24680 KB Output is correct
28 Correct 66 ms 17840 KB Output is correct
29 Correct 1542 ms 23564 KB Output is correct
30 Correct 1412 ms 23152 KB Output is correct
31 Correct 601 ms 20056 KB Output is correct
32 Correct 576 ms 20644 KB Output is correct
33 Correct 5583 ms 36104 KB Output is correct
34 Correct 5710 ms 35812 KB Output is correct
35 Correct 4708 ms 33240 KB Output is correct
36 Correct 1579 ms 27188 KB Output is correct
37 Correct 1584 ms 27044 KB Output is correct
38 Correct 1787 ms 28920 KB Output is correct