This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "teams.h"
#include <string.h>
#define N 100000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N * 2];
int compare_x(int i, int j) { return xx[i] - xx[j]; }
int compare_k(int k1, int k2) { return k1 - k2; }
int (*compare)(int, int);
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) {
int c = compare(ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
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 ii[N * 2], n;
void init(int n_, int ll[], int rr[]) {
int i;
n = n_;
for (i = 0; i < n * 2; i++) {
xx[i] = (i & 1) == 0 ? ll[i >> 1] : rr[i >> 1] + 1;
ii[i] = i;
}
compare = compare_x, sort(ii, 0, n * 2);
}
int iq[1 + N], pq[N], cnt;
int lt(int i, int j) { return xx[i << 1 | 1] < xx[j << 1 | 1]; }
int p2(int p) {
return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}
void pq_up(int i) {
int p, q, j;
for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_dn(int i) {
int p, q, j;
for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_add(int i) {
pq[i] = ++cnt, pq_up(i);
}
void pq_remove(int i) {
if (pq[i]) {
int j = iq[cnt--];
if (j != i)
pq[j] = pq[i], pq_up(j), pq_dn(j);
pq[i] = 0;
}
}
void pq_remove_first() {
pq_remove(iq[1]);
}
int can(int m, int kk[]) {
int h, i;
compare = compare_k, sort(kk, 0, m);
memset(pq, 0, n * sizeof *pq), cnt = 0;
for (h = 0, i = 0; h < m; h++) {
while (i < n * 2 && xx[ii[i]] <= kk[h]) {
int i_ = ii[i++];
if ((i_ & 1) == 0)
pq_add(i_ >> 1);
else
pq_remove(i_ >> 1);
}
if (cnt < kk[h])
return 0;
while (kk[h]--)
pq_remove_first();
}
return 1;
}
Compilation message (stderr)
teams.c: In function 'rand_':
teams.c:9:18: warning: conversion to 'int' from 'unsigned int' may change the sign of the result [-Wsign-conversion]
9 | return (X *= 3) >> 1;
| ~~~~~~~~~^~~~
teams.c: In function 'can':
teams.c:100:18: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
100 | memset(pq, 0, n * sizeof *pq), cnt = 0;
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |