//I wrote this code 4 u today
#include <bits/stdc++.h>
#define vc vector
#define nd node*
#define pnd pair<nd, nd>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vc<pll> vpll;
typedef vc<vll> vvll;
typedef vc<vpll> vvpll;
template<const ll MOD>
struct mod_mul : multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
struct DSU {
static const int MAXN = 200005;
vc<int> down[MAXN];
int p[MAXN], f[MAXN], s[MAXN];
DSU() { iota(p, p + MAXN, 0); }
int get(int v) { return p[v] == v ? v : p[v] = get(p[v]); }
void merge(int v, int u) {//v->u
v = get(v), u = get(u);
if (v == u) return;
p[u] = v, down[v].push_back(u);
}
vc<int> ei;
void dfs(int v) {
f[v] = ei.size();
ei.push_back(v);
for (auto to: down[v]) dfs(to);
s[v] = ei.size();
}
void build_tour() {
for (int v = 0; v < MAXN; ++v) if (get(v) == v) dfs(v);
}
};
int n;
vc<int> t[200005 * 4];
void build(vc<int> &x, int l = 0, int r = n - 1, int v = 1) {
if (l == r) return void(t[v] = {x[l]});
int mid = (l + r) / 2;
build(x, l, mid, v * 2), build(x, mid + 1, r, v * 2 + 1);
t[v].resize(t[v * 2].size() + t[v * 2 + 1].size());
merge(t[v * 2].begin(), t[v * 2].end(), t[v * 2 + 1].begin(), t[v * 2 + 1].end(), t[v].begin());
}
bool check(int l_, int r_, int a, int b, int l = 0, int r = n - 1, int v = 1) {
if (l_ <= l && r <= r_) {
auto y = lower_bound(t[v].begin(), t[v].end(), a);
return y != t[v].end() && *y <= b;
}
if (r < l_ || r_ < l) return false;
int mid = (l + r) / 2;
return check(l_, r_, a, b, l, mid, v * 2) || check(l_, r_, a, b, mid + 1, r, v * 2 + 1);
}
vector<int>
check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
::n = N;
vc<vc<int>> s(N), l(N);
DSU a, b;
for (int i = 0; i < X.size(); ++i) {
if (X[i] < Y[i]) swap(X[i], Y[i]);
s[X[i]].push_back(Y[i]);
l[Y[i]].push_back(X[i]);
}
vc<int> t1(S.size()), t2(S.size());
vc<int> ord(S.size());
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](const int &i, const int &j) { return R[i] < R[j]; });
int j = 0;
for (int v = 0; v < N; ++v) {
for (auto to: s[v]) a.merge(v, to);
while (j < ord.size() && R[ord[j]] == v) t1[ord[j]] = a.get(E[ord[j]]), ++j;
}
sort(ord.begin(), ord.end(), [&](const int &i, const int &j) { return L[i] > L[j]; }), j = 0;
for (int v = N - 1; v >= 0; --v) {
for (auto to: l[v]) b.merge(v, to);
while (j < ord.size() && L[ord[j]] == v) t2[ord[j]] = b.get(S[ord[j]]), ++j;
}
a.build_tour(), b.build_tour();
vc<int> ans(S.size());
vc<int> wh(N);
for (int i = 0; i < N; ++i) wh[b.ei[i]] = i;
vc<int> bip(N);
for (int i = 0; i < N; ++i) {
bip[i] = wh[a.ei[i]];
}
build(bip);
for (int i = 0; i < ans.size(); ++i) {
ans[i] = check(a.f[t1[i]], a.s[t1[i]] - 1, b.f[t2[i]], b.s[t2[i]] - 1);
}
return ans;
}
#ifdef VOVA
namespace {
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
} // namespace
int main() {
int N = read_int();
int M = read_int();
int Q = read_int();
vector<int> X(M), Y(M), S(Q), E(Q), L(Q), R(Q);
for (int j = 0; j < M; ++j) {
X[j] = read_int();
Y[j] = read_int();
}
for (int i = 0; i < Q; ++i) {
S[i] = read_int();
E[i] = read_int();
L[i] = read_int();
R[i] = read_int();
}
vector<int> A = check_validity(N, X, Y, S, E, L, R);
for (size_t i = 0; i < A.size(); ++i) {
printf("%d\n", A[i]);
}
return 0;
}
#endif
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:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for (int i = 0; i < X.size(); ++i) {
| ~~^~~~~~~~~~
werewolf.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | while (j < ord.size() && R[ord[j]] == v) t1[ord[j]] = a.get(E[ord[j]]), ++j;
| ~~^~~~~~~~~~~~
werewolf.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | while (j < ord.size() && L[ord[j]] == v) t2[ord[j]] = b.get(S[ord[j]]), ++j;
| ~~^~~~~~~~~~~~
werewolf.cpp:126:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | for (int i = 0; i < ans.size(); ++i) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
35528 KB |
Output is correct |
2 |
Correct |
24 ms |
35484 KB |
Output is correct |
3 |
Correct |
21 ms |
35464 KB |
Output is correct |
4 |
Correct |
25 ms |
35452 KB |
Output is correct |
5 |
Correct |
20 ms |
35436 KB |
Output is correct |
6 |
Correct |
21 ms |
35528 KB |
Output is correct |
7 |
Correct |
20 ms |
35528 KB |
Output is correct |
8 |
Correct |
22 ms |
35432 KB |
Output is correct |
9 |
Correct |
20 ms |
35528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
35528 KB |
Output is correct |
2 |
Correct |
24 ms |
35484 KB |
Output is correct |
3 |
Correct |
21 ms |
35464 KB |
Output is correct |
4 |
Correct |
25 ms |
35452 KB |
Output is correct |
5 |
Correct |
20 ms |
35436 KB |
Output is correct |
6 |
Correct |
21 ms |
35528 KB |
Output is correct |
7 |
Correct |
20 ms |
35528 KB |
Output is correct |
8 |
Correct |
22 ms |
35432 KB |
Output is correct |
9 |
Correct |
20 ms |
35528 KB |
Output is correct |
10 |
Correct |
30 ms |
36100 KB |
Output is correct |
11 |
Correct |
27 ms |
36032 KB |
Output is correct |
12 |
Correct |
42 ms |
35956 KB |
Output is correct |
13 |
Correct |
26 ms |
36192 KB |
Output is correct |
14 |
Correct |
48 ms |
36152 KB |
Output is correct |
15 |
Correct |
26 ms |
36200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
676 ms |
98656 KB |
Output is correct |
2 |
Correct |
533 ms |
100828 KB |
Output is correct |
3 |
Correct |
643 ms |
99448 KB |
Output is correct |
4 |
Correct |
541 ms |
98780 KB |
Output is correct |
5 |
Correct |
615 ms |
98828 KB |
Output is correct |
6 |
Correct |
717 ms |
98684 KB |
Output is correct |
7 |
Correct |
660 ms |
98708 KB |
Output is correct |
8 |
Correct |
595 ms |
100764 KB |
Output is correct |
9 |
Correct |
599 ms |
99432 KB |
Output is correct |
10 |
Correct |
475 ms |
98784 KB |
Output is correct |
11 |
Correct |
508 ms |
98832 KB |
Output is correct |
12 |
Correct |
690 ms |
98776 KB |
Output is correct |
13 |
Correct |
647 ms |
109864 KB |
Output is correct |
14 |
Correct |
607 ms |
109868 KB |
Output is correct |
15 |
Correct |
658 ms |
109860 KB |
Output is correct |
16 |
Correct |
618 ms |
109796 KB |
Output is correct |
17 |
Correct |
737 ms |
98808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
35528 KB |
Output is correct |
2 |
Correct |
24 ms |
35484 KB |
Output is correct |
3 |
Correct |
21 ms |
35464 KB |
Output is correct |
4 |
Correct |
25 ms |
35452 KB |
Output is correct |
5 |
Correct |
20 ms |
35436 KB |
Output is correct |
6 |
Correct |
21 ms |
35528 KB |
Output is correct |
7 |
Correct |
20 ms |
35528 KB |
Output is correct |
8 |
Correct |
22 ms |
35432 KB |
Output is correct |
9 |
Correct |
20 ms |
35528 KB |
Output is correct |
10 |
Correct |
30 ms |
36100 KB |
Output is correct |
11 |
Correct |
27 ms |
36032 KB |
Output is correct |
12 |
Correct |
42 ms |
35956 KB |
Output is correct |
13 |
Correct |
26 ms |
36192 KB |
Output is correct |
14 |
Correct |
48 ms |
36152 KB |
Output is correct |
15 |
Correct |
26 ms |
36200 KB |
Output is correct |
16 |
Correct |
676 ms |
98656 KB |
Output is correct |
17 |
Correct |
533 ms |
100828 KB |
Output is correct |
18 |
Correct |
643 ms |
99448 KB |
Output is correct |
19 |
Correct |
541 ms |
98780 KB |
Output is correct |
20 |
Correct |
615 ms |
98828 KB |
Output is correct |
21 |
Correct |
717 ms |
98684 KB |
Output is correct |
22 |
Correct |
660 ms |
98708 KB |
Output is correct |
23 |
Correct |
595 ms |
100764 KB |
Output is correct |
24 |
Correct |
599 ms |
99432 KB |
Output is correct |
25 |
Correct |
475 ms |
98784 KB |
Output is correct |
26 |
Correct |
508 ms |
98832 KB |
Output is correct |
27 |
Correct |
690 ms |
98776 KB |
Output is correct |
28 |
Correct |
647 ms |
109864 KB |
Output is correct |
29 |
Correct |
607 ms |
109868 KB |
Output is correct |
30 |
Correct |
658 ms |
109860 KB |
Output is correct |
31 |
Correct |
618 ms |
109796 KB |
Output is correct |
32 |
Correct |
737 ms |
98808 KB |
Output is correct |
33 |
Correct |
798 ms |
98104 KB |
Output is correct |
34 |
Correct |
297 ms |
55800 KB |
Output is correct |
35 |
Correct |
813 ms |
100136 KB |
Output is correct |
36 |
Correct |
704 ms |
99208 KB |
Output is correct |
37 |
Correct |
714 ms |
99268 KB |
Output is correct |
38 |
Correct |
709 ms |
99644 KB |
Output is correct |
39 |
Correct |
721 ms |
106640 KB |
Output is correct |
40 |
Correct |
821 ms |
106440 KB |
Output is correct |
41 |
Correct |
672 ms |
98892 KB |
Output is correct |
42 |
Correct |
601 ms |
99140 KB |
Output is correct |
43 |
Correct |
709 ms |
104620 KB |
Output is correct |
44 |
Correct |
770 ms |
99376 KB |
Output is correct |
45 |
Correct |
689 ms |
106932 KB |
Output is correct |
46 |
Correct |
626 ms |
106764 KB |
Output is correct |
47 |
Correct |
794 ms |
109944 KB |
Output is correct |
48 |
Correct |
690 ms |
109828 KB |
Output is correct |
49 |
Correct |
630 ms |
109940 KB |
Output is correct |
50 |
Correct |
621 ms |
109876 KB |
Output is correct |
51 |
Correct |
733 ms |
105760 KB |
Output is correct |
52 |
Correct |
738 ms |
105736 KB |
Output is correct |