# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485397 |
2021-11-07T15:47:04 Z |
rainboy |
Kosta (COI14_kosta) |
C |
|
206 ms |
13728 KB |
#include <stdio.h>
#define N1 200000
#define N2 50000
#define LG 16 /* LG = ceil(log2(N2)) */
#define N_ (1 + N2 * (LG + 1))
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int abs_(int a) { return a > 0 ? a : -a; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int *zz;
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (zz[ii[j]] == zz[i_])
j++;
else if (zz[ii[j]] < zz[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int ll[N_], rr[N_], kk[N_];
int update(int t, int l, int r, int i) {
static int _ = 1;
int t_ = _++;
kk[t_] = kk[t] + 1;
if (r - l > 1) {
int m = (l + r) / 2;
if (i < m)
ll[t_] = update(ll[t], l, m, i), rr[t_] = rr[t];
else
ll[t_] = ll[t], rr[t_] = update(rr[t], m, r, i);
}
return t_;
}
int query(int t, int l, int r, int ql, int qr) {
int m;
if (qr <= l || r <= ql || t == 0)
return 0;
if (ql <= l && r <= qr)
return kk[t];
m = (l + r) / 2;
return query(ll[t], l, m, ql, qr) + query(rr[t], m, r, ql, qr);
}
int xx[N1], yy[N1], xx_[N2], yy_[N2], ii[N2], jj[N2], tt[N2], n;
int t, i1, i2;
int check(int d_) {
if (t == 1) {
int i, xmn, xmx, ymn, ymx;
xmn = INF, xmx = -INF, ymn = INF, ymx = -INF;
for (i = 0; i < n; i++) {
xmn = min(xmn, xx[i]), xmx = max(xmx, xx[i]);
ymn = min(ymn, yy[i]), ymx = max(ymx, yy[i]);
}
for (i1 = 0; i1 < n; i1++)
if (xx[i1] - xmn <= d_ && xmx - xx[i1] <= d_ && yy[i1] - ymn <= d_ && ymx - yy[i1] <= d_)
return 1;
return 0;
} else {
static int iil[N2], iir[N2], iid[N2], iiu[N2], iil_[N2], iir_[N2], iid_[N2], iiu_[N2];
int i, i_, j, j_, l, r, d, u;
for (i = 0, j = 0; j < n; j++) {
while (i < n && xx[ii[j]] - xx[ii[i]] > d_)
i++;
iil[ii[j]] = i;
}
for (i = n - 1, j = n - 1; i >= 0; i--) {
while (j >= 0 && xx[ii[j]] - xx[ii[i]] > d_)
j--;
iir[ii[i]] = j;
}
for (i = 0, j = 0; j < n; j++) {
while (i < n && yy[jj[j]] - yy[jj[i]] > d_)
i++;
iid[jj[j]] = i;
}
for (i = n - 1, j = n - 1; i >= 0; i--) {
while (j >= 0 && yy[jj[j]] - yy[jj[i]] > d_)
j--;
iiu[jj[i]] = j;
}
for (i = 0; i < n; i++)
iil_[i] = 0, iir_[i] = n - 1, iid_[i] = 0, iiu_[i] = n - 1;
l = 0, r = n - 1, d = 0, u = n - 1;
for (i = 0, j = 0; j < n; j++) {
j_ = ii[j];
while (i < n && xx[j_] - xx[i_ = ii[i]] > d_) {
l = max(l, iil[i_]), r = min(r, iir[i_]);
d = max(d, iid[i_]), u = min(u, iiu[i_]);
i++;
}
iil_[j_] = max(iil_[j_], l), iir_[j_] = min(iir_[j_], r);
iid_[j_] = max(iid_[j_], d), iiu_[j_] = min(iiu_[j_], u);
}
l = 0, r = n - 1, d = 0, u = n - 1;
for (i = n - 1, j = n - 1; i >= 0; i--) {
i_ = ii[i];
while (j >= 0 && xx[j_ = ii[j]] - xx[i_] > d_) {
l = max(l, iil[j_]), r = min(r, iir[j_]);
d = max(d, iid[j_]), u = min(u, iiu[j_]);
j--;
}
iil_[i_] = max(iil_[i_], l), iir_[i_] = min(iir_[i_], r);
iid_[i_] = max(iid_[i_], d), iiu_[i_] = min(iiu_[i_], u);
}
l = 0, r = n - 1, d = 0, u = n - 1;
for (i = 0, j = 0; j < n; j++) {
j_ = jj[j];
while (i < n && yy[j_] - yy[i_ = jj[i]] > d_) {
l = max(l, iil[i_]), r = min(r, iir[i_]);
d = max(d, iid[i_]), u = min(u, iiu[i_]);
i++;
}
iil_[j_] = max(iil_[j_], l), iir_[j_] = min(iir_[j_], r);
iid_[j_] = max(iid_[j_], d), iiu_[j_] = min(iiu_[j_], u);
}
l = 0, r = n - 1, d = 0, u = n - 1;
for (i = n - 1, j = n - 1; i >= 0; i--) {
i_ = jj[i];
while (j >= 0 && yy[j_ = jj[j]] - yy[i_] > d_) {
l = max(l, iil[j_]), r = min(r, iir[j_]);
d = max(d, iid[j_]), u = min(u, iiu[j_]);
j--;
}
iil_[i_] = max(iil_[i_], l), iir_[i_] = min(iir_[i_], r);
iid_[i_] = max(iid_[i_], d), iiu_[i_] = min(iiu_[i_], u);
}
for (i1 = 0; i1 < n; i1++) {
int l = iil_[i1], r = iir_[i1], d = iid_[i1], u = iiu_[i1];
if (l <= r && d <= u && query(tt[r], 0, n, d, u + 1) - (l == 0 ? 0 : query(tt[l - 1], 0, n, d, u + 1)) > 0) {
for (i2 = 0; i2 < n; i2++)
if (xx_[i2] >= l && xx_[i2] <= r && yy_[i2] >= d && yy_[i2] <= u)
break;
return 1;
}
}
return 0;
}
}
int main() {
int i, j, lower, upper;
scanf("%d%d", &t, &n);
for (i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
xx[i] = x + y, yy[i] = x - y;
}
if (t == 2) {
for (i = 0; i < n; i++)
ii[i] = i;
zz = xx, sort(ii, 0, n);
for (i = 0; i < n; i++)
xx_[ii[i]] = i;
for (j = 0; j < n; j++)
jj[j] = j;
zz = yy, sort(jj, 0, n);
for (j = 0; j < n; j++)
yy_[jj[j]] = j;
for (i = 0; i < n; i++)
tt[i] = update(i == 0 ? 0 : tt[i - 1], 0, n, yy_[ii[i]]);
}
lower = -1, upper = INF;
while (upper - lower > 1) {
int d = (lower + upper) / 2;
if (check(d))
upper = d;
else
lower = d;
}
check(upper);
printf("%d\n", upper);
if (t == 1)
printf("%d\n", i1 + 1);
else
printf("%d %d\n", i1 + 1, i2 + 1);
return 0;
}
Compilation message
kosta.c: In function 'main':
kosta.c:173:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
173 | scanf("%d%d", &t, &n);
| ^~~~~~~~~~~~~~~~~~~~~
kosta.c:177:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
177 | scanf("%d%d", &x, &y);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
1156 KB |
Output is correct |
2 |
Correct |
57 ms |
1216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
1732 KB |
Output is correct |
2 |
Correct |
74 ms |
1784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
976 KB |
Output is correct |
2 |
Correct |
10 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
988 KB |
Output is correct |
2 |
Correct |
10 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
10308 KB |
Output is correct |
2 |
Correct |
148 ms |
10952 KB |
Output is correct |
3 |
Correct |
185 ms |
10860 KB |
Output is correct |
4 |
Correct |
159 ms |
10940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
11712 KB |
Output is correct |
2 |
Correct |
184 ms |
12352 KB |
Output is correct |
3 |
Correct |
206 ms |
13468 KB |
Output is correct |
4 |
Correct |
203 ms |
13728 KB |
Output is correct |