#include <stdio.h>
#define N 100000
#define H 17 /* H = ceil(log2(N)) */
#define MD 365
int min(int a, int b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int dd[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int idx(int m, int d) {
int h;
for (h = 0; h < m; h++)
d += dd[h];
return d;
}
int ll[N], rr[N];
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 (ll[ii[j]] == ll[i_])
j++;
else if (ll[ii[j]] < ll[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 contains(int l1, int r1, int l2, int r2) {
if (l1 > r1)
r1 += MD;
if (l2 > r2)
r2 += MD;
if (l2 < l1)
l2 += MD, r2 += MD;
return l1 <= l2 && r2 <= r1;
}
int main() {
static int ii[N], jj[H + 1][N], dd[H + 1][N];
int n, n_, l_, r_, h, i, i_, j, k, k_, l, r, d;
scanf("%d", &n), l_ = idx(2, 0), r_ = idx(10, 29);
for (i = 0; i < n; i++) {
int ml, dl, mr, dr;
scanf("%d%d%d%d", &ml, &dl, &mr, &dr), ml--, dl--, mr--, dr--;
ll[i] = idx(ml, dl), rr[i] = idx(mr, dr);
}
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
n_ = 0;
for (i = 0; i < n; i++)
if (n_ == 0 || !contains(ll[ii[n_ - 1]], rr[ii[n_ - 1]], ll[ii[i]], rr[ii[i]])) {
if (n_ > 0 && ll[ii[n_ - 1]] == ll[ii[i]])
ii[n_ - 1] = ii[i];
else
ii[n_++] = ii[i];
}
i_ = 0;
while (i_ + 1 < n_ && contains(ll[ii[n_ - 1]], rr[ii[n_ - 1]], ll[ii[i_]], rr[ii[i_]]))
i_++;
for (i = 0; i + i_ < n_; i++)
ii[i] = ii[i + i_];
n_ -= i_;
for (i = 0, j = 0; i < n_; i++) {
while (j < i + n_ && contains(ll[ii[i]], rr[ii[i]], ll[ii[j % n_]], ll[ii[j % n_]]))
j++;
jj[0][i] = (j - 1) % n_, dd[0][i] = (rr[ii[(j - 1) % n_]] - rr[ii[i]] + MD) % MD;
}
for (h = 0; h < H; h++)
for (i = 0; i < n_; i++) {
jj[h + 1][i] = jj[h][jj[h][i]];
dd[h + 1][i] = dd[h][i] + dd[h][jj[h][i]];
}
k_ = n_ + 1;
for (i = 0; i < n_; i++) {
l = ll[ii[i]], r = rr[ii[i]];
if (contains(l, r, l_, r_)) {
printf("1\n");
return 0;
}
if (!contains(l, r, l_, l_))
continue;
d = contains(l, r, r_, r_) ? MD - ((r - l + MD) % MD + 1) : (r_ - r) % MD;
if (d == 0) {
printf("1\n");
return 0;
}
if (dd[H][i] < d)
continue;
i_ = i, k = 2;
for (h = H; h >= 0; h--)
if (dd[h][i_] < d)
k += 1 << h, d -= dd[h][i_], i_ = jj[h][i_];
k_ = min(k_, k);
}
if (k_ == n_ + 1)
k_ = 0;
printf("%d\n", k_);
return 0;
}
Compilation message
flower.c: In function 'main':
flower.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d", &n), l_ = idx(2, 0), r_ = idx(10, 29);
| ^~~~~~~~~~~~~~~
flower.c:64:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | scanf("%d%d%d%d", &ml, &dl, &mr, &dr), ml--, dl--, mr--, dr--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
724 KB |
Output is correct |
2 |
Correct |
7 ms |
852 KB |
Output is correct |
3 |
Correct |
14 ms |
1108 KB |
Output is correct |
4 |
Correct |
13 ms |
1228 KB |
Output is correct |
5 |
Correct |
17 ms |
1528 KB |
Output is correct |
6 |
Incorrect |
21 ms |
1720 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |