# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722768 | rainboy | Card Scoring (CCO19_day2problem1) | C11 | 0 ms | 0 KiB |
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 <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int *xx[N]; double *yy[N]; int cnt[N], cnt_[N], xx_[N], n; double k;
int crossover(int x1, double y1, int x2, double y2) {
int lower = x2, upper = n + 1;
while (upper - lower > 1) {
int x = (lower + upper) / 2;
if (y1 + pow(x - x1, k) >= y2 + pow(x - x2, k))
upper = x;
else
lower = x;
}
return upper;
}
void add(int a, double y) {
while (cnt[a] && crossover(xx[a][cnt[a] - 2], yy[a][cnt[a] - 2], xx[a][cnt[a] - 1], yy[a][cnt[a] - 1]) <= crossover(xx[a][cnt[a] - 1], yy[a][cnt[a] - 1], xx_[a], y))
cnt[a]--;
if (cnt[a] == cnt_[a]) {
xx[a] = (int *) realloc(xx[a], cnt_[a] * 2 * sizeof *xx[a]);
yy[a] = (double *) realloc(yy[a], cnt_[a] * 2 * sizeof *yy[a]);
}
xx[a][cnt[a]] = xx_[a], yy[a][cnt[a]] = y, cnt[a]++;