#include "werewolf.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
struct node
{
int pos = 0;
vector<int> edges;
};
vector<node> g;
vector<int> kette;
struct segtree
{
pair<int, int> tree[800000];
pair<int, int> init(int index, int b, int e)
{
if (b == e - 1)
return tree[index] = {kette[b], kette[b]};
auto left = init(index * 2, b, (b + e) / 2);
auto right = init(index * 2 + 1, (b + e) / 2, e);
tree[index] = {min(right.first, left.first), max(right.second, left.second)};
return tree[index];
}
int fistindexbiggerthan(int index, int b, int e, int l, int r, int v)
{
if (r <= b || e <= l || tree[index].second <= v)
return INT32_MAX;
if (b == e - 1)
return b;
int x = fistindexbiggerthan(index * 2, b, (e + b) / 2, l, r, v);
if (x != INT32_MAX)
return x;
return fistindexbiggerthan(index * 2 + 1, (e + b) / 2, e, l, r, v);
}
int fistindexsmallerthan(int index, int b, int e, int l, int r, int v)
{
if (r <= b || e <= l || tree[index].first >= v)
return INT32_MAX;
if (b == e - 1)
return b;
int x = fistindexsmallerthan(index * 2, b, (e + b) / 2, l, r, v);
if (x != INT32_MAX)
return x;
return fistindexsmallerthan(index * 2 + 1, (e + b) / 2, e, l, r, v);
}
pair<int, int> query(int index, int b, int e, int l, int r)
{
if (l <= b && e <= r)
return tree[index];
if (r <= b || e <= l)
return {INT32_MAX, INT32_MIN};
auto left = query(index * 2, b, (b + e) / 2, l, r);
auto right = query(index * 2 + 1, (b + e) / 2, e, l, r);
return {min(right.first, left.first), max(right.second, left.second)};
}
} minmaxtree;
void kettenbau(int n, int from = -1)
{
g[n].pos = kette.size();
kette.push_back(n);
for (auto i : g[n].edges)
{
if (i != from)
kettenbau(i, n);
}
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R)
{
g.resize(N);
for (int i = 0; i < X.size(); i++)
{
g[X[i]].edges.push_back(Y[i]);
g[Y[i]].edges.push_back(X[i]);
}
int chainend = 0;
for (int i = 0; i < N; i++) // endenfinden
{
if (g[i].edges.size() == 1)
{
chainend = i;
break;
}
}
kettenbau(chainend);
minmaxtree.init(1, 0, N);
vector<int> out;
for (int i = 0; i < S.size(); i++)
{
int mensch = g[S[i]].pos;
int wolf = g[E[i]].pos;
if (mensch < wolf)
{
int b = minmaxtree.fistindexsmallerthan(1, 0, N, mensch, wolf + 1, L[i]) - 1;
/*
int b = mensch, e = wolf + 1;
while (b != e - 1) // b ist das letzte zu dem man noch als mensch kann
{
auto x = minmaxtree.query(1, 0, N, b, (b + e) / 2 + 1);
if (x.first >= L[i])
b = (b + e) / 2;
else
e = (b + e) / 2;
}*/
if (minmaxtree.query(1, 0, N, b, wolf + 1).second <= R[i])
out.push_back(1);
else
out.push_back(0);
}
else
{
int b = minmaxtree.fistindexbiggerthan(1, 0, N, wolf, mensch + 1, R[i]) - 1;
/*
int b = wolf, e = mensch + 1;
while (b != e - 1) // b ist das letzte zu dem man noch als mensch kann
{
auto x = minmaxtree.query(1, 0, N, b, (b + e) / 2 + 1);
if (x.second <= R[i])
b = (b + e) / 2;
else
e = (b + e) / 2;
}*/
if (minmaxtree.query(1, 0, N, b, mensch + 1).first >= L[i])
out.push_back(1);
else
out.push_back(0);
}
}
return out;
}
Compilation message
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i = 0; i < X.size(); i++)
| ~~^~~~~~~~~~
werewolf.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int i = 0; i < S.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
374 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
374 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
553 ms |
38032 KB |
Output is correct |
2 |
Correct |
332 ms |
46464 KB |
Output is correct |
3 |
Correct |
337 ms |
46392 KB |
Output is correct |
4 |
Correct |
390 ms |
46452 KB |
Output is correct |
5 |
Correct |
408 ms |
46420 KB |
Output is correct |
6 |
Correct |
447 ms |
46464 KB |
Output is correct |
7 |
Correct |
452 ms |
46396 KB |
Output is correct |
8 |
Correct |
366 ms |
46460 KB |
Output is correct |
9 |
Correct |
343 ms |
46448 KB |
Output is correct |
10 |
Correct |
363 ms |
46328 KB |
Output is correct |
11 |
Correct |
361 ms |
46392 KB |
Output is correct |
12 |
Correct |
348 ms |
46392 KB |
Output is correct |
13 |
Correct |
397 ms |
46392 KB |
Output is correct |
14 |
Correct |
405 ms |
46388 KB |
Output is correct |
15 |
Correct |
403 ms |
46356 KB |
Output is correct |
16 |
Correct |
408 ms |
46448 KB |
Output is correct |
17 |
Correct |
458 ms |
46364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
374 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |