QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414268#2581. 浙江省选Ecec243100 ✓356ms10600kbC++233.7kb2024-05-18 19:03:272024-05-18 19:03:31

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 19:03:31]
  • 评测
  • 测评结果:100
  • 用时:356ms
  • 内存:10600kb
  • [2024-05-18 19:03:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define Size(x) ((x).size())
#define rep(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define per(i, r, l) for(int (i) = (r); (i) >= (l); --(i))
#define chkmax(x, y) (x) = max((x), (y))
#define chkmin(x, y) (x) = min((x), (y))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> VI;
inline char gc() {
	static char now[1 << 16], *S, *T;
	if (S == T) {T = (S = now) + fread(now, 1, 1 << 16, stdin); if (S == T) return EOF;}
	return *S ++;
}
inline int readint() {
	int x = 0, f = 1; char c = gc();
	while (c < '0' || c > '9') {(c == '-') ? (f = 0) : 0; c = gc();}
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48); c = gc();}
	return f ? x : ((~ x) + 1);
}
inline ll readll() {
	ll x = 0, f = 1; char c = gc();
	while (c < '0' || c > '9') {(c == '-') ? (f = 0) : 0; c = gc();}
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48); c = gc();}
	return f ? x : ((~ x) + 1);
}
struct frac {
	ll x, y;
};
inline ll floor(const frac &A) {
	return A.x / A.y;
}
inline ll ceil(const frac &A) {
	return A.x / A.y + (A.x % A.y != 0);
}
inline bool operator < (const frac &A, const ll &B) {
	return (ld) A.x / A.y < (ld) B;
}
inline bool operator < (const frac &A, const frac &B) {
	return (ld) A.x / A.y < (ld) B.x / B.y;
}
inline frac make(const ll &x, const ll &y) {
	return (y > 0) ? (frac) {x, y} : (frac) {- x, - y};
}
const int N = 100010;
const ll inf = 1ll << 60;
int n, ans[N];
struct item {
	int k, id; ll b;
} a[N], stk[N];
int top;
inline bool operator < (const item &A, const item &B) {
	return (A.k ^ B.k) ? (A.k < B.k) : (A.b > B.b);
}
inline frac inter(const item &A, const item &B) {
	return make(B.b - A.b, A.k - B.k);
}
inline void halfplane() {
	top = 0;
	rep(i, 1, n) {
		if (ans[a[i].id] != -1) continue ;
		while (top >= 2 && inter(a[i], stk[top - 1]) < inter(stk[top], stk[top - 1])) -- top;
		if (top == 1 && a[i].b > stk[top].b) -- top;
		if (top == 0 || a[i].k != stk[top].k) stk[++ top] = a[i];
	}
}
pair<ll, int> que[N << 1]; int cnt;
int main() {
	n = readint(); int m = readint();
	rep(i, 1, n) {
		a[i].k = readint();
		a[i].b = readll();
		a[i].id = i;
		ans[i] = -1;
	}
	sort(a + 1, a + n + 1);
	rep(nowm, 1, m) {
		halfplane();
		if (!top) break ;
		stk[0] = stk[1]; stk[0].k = 0;
		int now = 0; cnt = 0;
		rep(i, 1, n) if (ans[a[i].id] != -1) {
			int l = 0, r = top;
			while (l < r) {
				int mid = (l + r + 1) >> 1;
				if (a[i].k <= stk[mid].k || inter(a[i], stk[mid - 1]) < inter(stk[mid], stk[mid - 1])) r = mid - 1;
				else l = mid;
			}
			if (l == 0) ++ now;
			else que[++ cnt] = mk(floor(inter(a[i], stk[l])) + 1, 1);
			if (a[i].k < stk[top].k) {
				l = 1, r = top + 1;
				while (l < r) {
					int mid = (l + r) >> 1;
					if (a[i].k >= stk[mid].k || (mid != top && inter(stk[mid], stk[mid + 1]) < inter(a[i], stk[mid + 1]))) l = mid + 1;
					else r = mid;
				}
				que[++ cnt] = mk(ceil(inter(a[i], stk[l])), -1);
			}
		}
		sort(que + 1, que + cnt + 1);
		int pos = 1;
		rep(i, 1, top) {
			ll l = ceil(inter(stk[i], stk[i - 1])),
			   r = i == top ? inf : floor(inter(stk[i], stk[i + 1]));
			if (l > r) continue;
			while (pos <= cnt && que[pos].fi <= l) {
				ll val = que[pos].fi;
				while (pos <= cnt && que[pos].fi == val) now += que[pos ++].se;
			}
			int mn = now;
			while (pos <= cnt && que[pos].fi <= r) {
				ll val = que[pos].fi;
				while (pos <= cnt && que[pos].fi == val) now += que[pos ++].se;
				chkmin(mn, now);
			}
			if (mn == nowm - 1) ans[stk[i].id] = nowm;
		}
	}
	for (int i = 1; i <= n; ++ i) printf("%d ", ans[i]);
	return 0;
}

详细

Test #1:

score: 10
Accepted
time: 2ms
memory: 7892kb

input:

200 20
999980116 499972659661732832
999976382 499985954590784341
999989500 499925628313372149
999969174 499998188932933085
999993007 499901652814140492
999990405 499919713063836435
999985157 499951191391405214
999988856 499929777538026104
999983505 499959193478550562
999997425 499868325384982983
999...

output:

13 3 1 1 13 1 9 1 1 5 1 4 10 1 2 4 8 8 1 8 2 9 12 8 7 11 1 4 1 18 8 10 7 5 15 17 18 9 5 6 1 8 1 1 1 4 1 6 6 10 5 2 2 1 1 1 1 1 1 1 14 1 5 8 13 2 8 1 1 12 14 7 5 1 19 9 6 1 8 20 8 1 7 6 1 4 4 5 1 1 15 7 -1 1 15 1 11 1 8 1 1 1 1 1 2 1 1 1 3 2 14 1 1 1 2 1 7 4 6 6 1 2 1 5 3 1 13 8 6 20 10 3 1 3 2 5 5 5...

result:

ok 200 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 7876kb

input:

200 20
999987497 499948437833472521
999996959 499868998184523935
999994358 499893870645923033
999975699 499997452465640324
999991019 499922692912995747
999995590 499882342299620979
999992660 499908940075973527
999993430 499902451634211649
999988597 499940942406206565
999984338 499966668609284350
999...

output:

6 10 1 1 2 1 15 1 1 10 1 3 11 1 19 6 15 11 1 17 3 2 10 3 2 5 1 16 1 7 10 14 11 8 3 12 7 5 7 4 1 5 5 1 1 2 1 3 20 6 15 3 5 1 3 12 9 1 2 1 8 1 4 8 5 8 3 11 1 9 17 5 3 1 7 9 6 6 4 17 6 1 3 5 1 6 4 13 1 1 12 9 20 3 5 1 4 1 6 1 1 1 1 1 6 1 1 1 5 6 9 1 1 1 8 1 2 5 15 20 1 2 1 12 3 2 7 4 4 15 3 4 1 13 3 17...

result:

ok 200 numbers

Test #3:

score: 10
Accepted
time: 20ms
memory: 8964kb

input:

100000 1
995507459 455461230768415462
992113796 476633897430149354
990046675 486176517140632308
990693952 483456835323367192
992902690 472331671443411224
984426621 499579245114571350
996609686 447080228327473793
996775878 445749287086756631
997240803 441933882373646908
984490644 499532148643458218
9...

output:

-1 -1 1 -1 1 1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 ...

result:

ok 100000 numbers

Test #4:

score: 10
Accepted
time: 30ms
memory: 10048kb

input:

100000 2
991412670 480971937820254236
990880886 483399967849466650
990132926 486534602121455050
999529192 422379939305725616
993003091 472698023255462877
984537783 499583410039053084
996659737 447784159070513814
993493013 469843173063053612
997292212 442621199841168574
983882910 499918568849841652
9...

output:

2 -1 1 2 1 1 1 2 1 -1 2 1 2 -1 -1 -1 2 1 -1 2 -1 1 2 -1 2 1 1 2 2 1 2 -1 1 2 2 1 -1 -1 2 2 1 2 1 2 2 1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 2 1 2 1 2 2 1 1 2 2 -1 2 -1 2 2 1 2 1 2 2 1 2 -1 -1 -1 2 2 2 2 2 1 2 -1 2 -1 -1 1 2 -1 -1 1 -1 1 1 1 2 2 1 2 1 2 2 2 2 2 2 1 2 2 -1 1 -1 2 1 -1 2 1 1 -1 -1 -1 2 -1 -1 -1...

result:

ok 100000 numbers

Test #5:

score: 10
Accepted
time: 33ms
memory: 10480kb

input:

100000 2
993979270 465977847440576160
992153425 476514540732474764
990125819 485932319628220600
987618793 494261753424974214
993002754 471860182660680431
984405696 499583238418368572
996693586 446523662746693063
997730070 437915129050162848
997324133 441366872041690270
986522031 496761743896734778
9...

output:

-1 -1 1 2 1 1 1 2 1 -1 2 1 2 -1 -1 2 -1 1 2 2 2 1 2 2 2 1 1 2 2 1 2 -1 1 -1 2 1 2 2 2 2 1 2 1 -1 2 1 2 1 -1 1 2 1 1 1 2 -1 2 -1 1 2 1 2 2 1 1 -1 2 -1 2 2 2 2 1 -1 1 -1 2 1 2 2 2 -1 2 -1 2 2 -1 1 2 2 2 -1 2 1 2 2 2 1 2 1 1 1 2 2 1 -1 1 2 -1 2 2 2 -1 1 2 2 2 1 2 -1 1 -1 -1 1 1 -1 2 -1 2 2 -1 2 -1 2 -1...

result:

ok 100000 numbers

Test #6:

score: 10
Accepted
time: 6ms
memory: 6076kb

input:

2000 20
999690756 499999980079580740
999775793 499873343152178009
999778568 499865302268434254
999995457 498498597452482161
999934310 499038858171140096
999695605 499999606074819495
999737663 499961024493174409
999840451 499619042463667628
999740635 499955554888202950
999985048 498599813549261950
99...

output:

6 10 8 7 11 1 5 1 1 16 1 4 14 1 5 3 5 3 5 4 2 1 10 11 2 1 8 12 1 7 6 1 5 1 1 3 5 1 11 3 5 9 1 5 14 2 4 1 1 6 1 1 11 1 4 3 8 6 1 7 5 3 4 3 5 1 4 1 1 1 4 8 3 1 4 4 5 14 3 1 1 1 3 1 2 1 2 2 3 1 9 1 2 4 6 3 7 1 14 13 1 1 3 1 1 1 1 3 8 13 7 2 8 8 5 1 16 1 3 10 1 1 2 4 3 3 1 5 7 1 1 8 10 5 1 6 6 1 7 11 2 ...

result:

ok 2000 numbers

Test #7:

score: 10
Accepted
time: 6ms
memory: 7948kb

input:

2000 20
999857515 499442217910169774
999996751 498351198778209546
999861982 499416382519409859
999926501 498977495355549205
999912634 499083684501824224
999668735 499999517923456185
999792741 499751161104123027
999822533 499623037584244703
999720860 499950676106935227
999982172 498492522309909939
99...

output:

8 6 8 7 5 1 4 1 1 3 1 5 3 1 10 13 6 2 2 3 3 1 5 5 2 1 14 18 1 9 5 1 3 1 1 5 6 1 5 5 8 3 1 6 7 2 2 1 1 11 1 1 3 1 3 10 4 11 1 3 11 5 2 3 12 1 9 1 1 1 1 3 7 1 8 3 10 5 6 1 1 1 4 1 5 1 2 4 3 1 2 1 10 10 5 5 2 1 8 4 1 1 3 1 1 1 1 10 17 3 2 3 7 7 6 1 2 1 12 2 1 1 5 4 5 2 1 8 7 1 1 1 4 2 1 7 4 1 4 11 4 1 ...

result:

ok 2000 numbers

Test #8:

score: 10
Accepted
time: 256ms
memory: 10544kb

input:

100000 20
994194016 465089019609518895
990601847 484271213013156135
990113877 486298793771901625
998955032 427539093348470820
993022300 472184128416555754
984493251 499592034902389178
996692522 447108384170549374
995241010 458021458320090624
997323314 441964940831884209
985816253 498115041865025080
...

output:

2 7 1 3 1 1 1 2 1 2 2 1 2 2 3 2 2 1 2 2 2 1 2 3 2 1 1 3 3 1 4 3 1 3 3 1 5 5 2 3 1 3 1 2 2 1 4 1 2 1 2 1 1 1 2 3 3 2 1 2 1 2 2 1 1 2 2 3 2 5 3 2 1 5 1 2 3 1 2 2 3 2 4 2 4 4 2 1 2 2 2 5 4 1 3 5 2 1 2 1 1 1 2 3 1 5 1 2 4 4 3 2 9 1 2 2 5 1 2 2 1 3 11 1 1 4 4 5 2 4 4 2 2 2 4 1 1 3 2 4 1 3 1 2 4 2 4 1 3 1...

result:

ok 100000 numbers

Test #9:

score: 10
Accepted
time: 354ms
memory: 10424kb

input:

100000 20
999358080 423877884566661828
988380483 492448813591823441
990186930 486115047228590389
997003638 444740269124513590
993064589 472029894394627734
984550467 499556349874036292
996771536 446611200263825377
984913282 499251341911028111
997409545 441388089558451129
987907757 493789514112618884
...

output:

11 2 1 4 1 1 1 4 1 3 3 1 2 8 4 4 6 1 4 3 4 1 2 2 6 1 1 2 3 1 2 2 1 6 3 1 15 6 2 6 1 2 1 3 5 1 3 1 7 1 2 1 1 1 5 5 3 8 1 2 1 3 4 1 1 2 3 11 3 6 3 8 1 12 1 2 6 1 5 3 5 6 4 4 10 6 2 1 11 7 3 9 3 1 3 5 7 1 3 1 1 1 2 2 1 10 1 3 3 2 10 8 7 1 4 2 7 1 2 2 1 12 5 1 1 5 4 4 4 3 4 4 5 2 11 1 1 2 3 12 1 8 1 6 5...

result:

ok 100000 numbers

Test #10:

score: 10
Accepted
time: 356ms
memory: 10600kb

input:

100000 20
998038972 434931362827770295
989074547 489885992919831175
990136687 485861927989975087
994132971 464750394429605174
992997200 471704021396665443
984525695 499556949147873700
996697926 446219522921688375
984926010 499207489074422449
997339652 440952463300399554
984695846 499421070165356264
...

output:

6 3 1 4 1 1 1 3 1 3 5 1 5 5 2 2 3 1 2 4 2 1 4 5 4 1 1 4 5 1 2 6 1 3 3 1 2 4 4 5 1 3 1 4 3 1 8 1 4 1 9 1 1 1 4 5 10 4 1 5 1 4 3 1 1 3 2 6 2 6 2 7 1 5 1 5 5 1 3 3 4 2 3 3 3 12 2 1 2 4 10 6 2 1 2 3 4 1 2 1 1 1 2 5 1 4 1 5 3 4 3 3 6 1 6 2 4 1 4 12 1 2 2 1 1 2 4 8 2 2 2 5 5 4 2 1 1 2 5 3 1 6 1 2 3 2 3 1 ...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed