이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "werewolf.h"
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef vector<int> vi;
const int N = 200000, Q = 200000;
int t;
int *ej[N], eo[N], *fj[N], fo[N];
void append(int **ej, int *eo, int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int ds[N], cc[N];
int find(int i) {
return ds[i] < 0 ? i : find(ds[i]);
}
void join(int i, int j, int c) {
i = find(i);
j = find(j);
if (i == j)
return;
if (ds[i] > ds[j]) {
ds[i] = j, cc[i] = c;
append(fj, fo, j, i);
} else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i, cc[j] = c;
append(fj, fo, i, j);
}
}
int ta[N], tb[N], qu[2][N], time;
void dfs(int i) {
int o;
qu[t][ta[i] = time++] = i;
for (o = 0; o < fo[i]; o++) {
int j = fj[i][o];
dfs(j);
}
tb[i] = time;
}
int ll_[2][Q], rr_[2][Q];
void get_segment(int i, int c, int *l, int *r) {
int lower, upper, o;
while (ds[i] >= 0 && cc[i] >= c)
i = ds[i];
lower = -1, upper = fo[i];
while (upper - lower > 1) {
int o = (lower + upper) / 2;
if (cc[fj[i][o]] >= c)
lower = o;
else
upper = o;
}
*l = ta[i], *r = lower == -1 ? ta[i] + 1 : tb[fj[i][lower]];
}
char used[N];
vi check_validity(int n, vi xx, vi yy, vi ss, vi ee, vi ll, vi rr) {
int m = xx.size(), q = ss.size(), h, h_, i, j, o;
vi ok(q);
for (t = 0; t < 2; t++) {
int tmp;
for (i = 0; i < n; i++) {
ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0;
fj[i] = (int *) malloc(2 * sizeof *fj[i]), fo[i] = 0;
}
for (h = 0; h < m; h++)
append(ej, eo, xx[h], yy[h]), append(ej, eo, yy[h], xx[h]);
memset(ds, -1, n * sizeof *ds);
for (i = n - 1; i >= 0; i--)
for (o = eo[i]; o--; ) {
j = ej[i][o];
if (i < j)
join(i, j, i);
}
time = 0;
for (i = 0; i < n; i++)
if (ds[i] < 0)
dfs(i);
for (h = 0; h < m; h++)
xx[h] = n - 1 - xx[h], yy[h] = n - 1 - yy[h];
for (h = 0; h < q; h++)
get_segment(ss[h], ll[h], &ll_[t][h], &rr_[t][h]);
for (h = 0; h < q; h++) {
tmp = ss[h], ss[h] = n - 1 - ee[h], ee[h] = n - 1 - tmp;
tmp = ll[h], ll[h] = n - 1 - rr[h], rr[h] = n - 1 - tmp;
}
}
for (i = 0; i < n; i++)
qu[1][i] = n - 1 - qu[1][i];
for (h = 0; h < q; h++) {
for (h_ = ll_[0][h]; h_ < rr_[0][h]; h_++)
used[qu[0][h_]] = 1;
for (h_ = ll_[1][h]; h_ < rr_[1][h]; h_++)
if (used[qu[1][h_]]) {
ok[h] = 1;
break;
}
for (h_ = ll_[0][h]; h_ < rr_[0][h]; h_++)
used[qu[0][h_]] = 0;
}
return ok;
}
컴파일 시 표준 에러 (stderr) 메시지
werewolf.cpp: In function 'void append(int**, int*, int, int)':
werewolf.cpp:18:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
18 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
werewolf.cpp: In function 'void get_segment(int, int, int*, int*)':
werewolf.cpp:62:20: warning: unused variable 'o' [-Wunused-variable]
62 | int lower, upper, o;
| ^
# | 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... |