#include <bits/stdc++.h>
#ifndef LOCAL
#include "werewolf.h"
#endif
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define Time (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
for (auto& x : v)
stream << x << ' ';
return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
return stream << p.first << ' ' << p.second;
}
const int INF32 = 1e9;
const int maxN = 200005;
int n, m, Q;
vector<int> G[maxN];
int timer;
int where[maxN];
vector<pii> hist[maxN];
vector<int> comp[maxN];
void joinR(int x, int y) {
x = where[x];
y = where[y];
if (x == y) return;
if (comp[x].size() < comp[y].size()) swap(x, y);
for (int v : comp[y]) {
where[v] = x;
while (!hist[v].empty() && hist[v].back().fi == timer)
hist[v].pop_back();
hist[v].emplace_back(timer, x);
comp[x].push_back(v);
}
comp[y].clear();
}
map<int, int> kek[maxN];
void joinL(int x, int y) {
x = where[x];
y = where[y];
if (x == y) return;
if (comp[x].size() < comp[y].size()) swap(x, y);
for (int v : comp[y]) {
where[v] = x;
comp[x].push_back(v);
}
for (auto el : kek[y]) {
int tau = el.se;
int c = el.fi;
if (!kek[x].count(c) || kek[x][c] > tau) {
kek[x][c] = tau;
}
}
comp[y].clear();
}
int getCompR(int v, int tau) {
int i = upper_bound(all(hist[v]), mp(tau, INF32)) - hist[v].begin() - 1;
return hist[v][i].se;
}
vector<int> queL[maxN];
vector<int> check_validity(int _n, vector<int> eu, vector<int> ev, vector<int> qs, vector<int> qt, vector<int> ql, vector<int> qr) {
n = _n;
m = eu.size();
Q = qs.size();
for (int j = 0; j < m; ++j) {
int u = eu[j], v = ev[j];
G[u].push_back(v);
G[v].push_back(u);
}
for (int r = 0; r < n; ++r) {
timer = r;
where[r] = r;
comp[r] = {r};
hist[r].emplace_back(timer, r);
for (int y : G[r])
if (y <= r) {
joinR(y, r);
}
}
// for (int v = 0; v < n; ++v)
// debug(v, hist[v]);
for (int i = 0; i < Q; ++i) {
if (qs[i] >= ql[i] && qt[i] <= qr[i])
queL[ql[i]].push_back(i);
}
for (int c = 0; c < n; ++c) {
comp[c].clear();
where[c] = -1;
}
vector<int> ans(Q, 0);
for (int l = n - 1; l >= 0; --l) {
where[l] = l;
comp[l] = {l};
for (auto el : hist[l])
kek[l][el.se] = el.fi;
for (int y : G[l])
if (y >= l)
joinL(y, l);
for (int i : queL[l]) {
int s = qs[i];
int t = qt[i];
int r = qr[i];
int ct = getCompR(t, r);
int ws = where[s];
// debug(ct);
// debug(ws, comp[ws]);
// cerr << "kek[ws] = "; for (auto el : kek[ws]) cerr << el << ' '; cerr << endl;
if (kek[ws].count(ct) && kek[ws][ct] <= r)
ans[i] = 1;
/*for (int v : comp[where[s]])
if (true) {
bool good = false;
for (auto el : hist[v]) {
if (el.se == ct && el.fi <= r) {
good = true;
break;
}
}
if (good) {
ans[i] = 1;
break;
}
}*/
}
}
return ans;
}
#ifdef LOCAL
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
int32_t main() {
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int N = read_int();
int M = read_int();
int Q = read_int();
std::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();
}
std::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
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
28492 KB |
Output is correct |
2 |
Correct |
18 ms |
28492 KB |
Output is correct |
3 |
Correct |
19 ms |
28500 KB |
Output is correct |
4 |
Correct |
20 ms |
28364 KB |
Output is correct |
5 |
Correct |
18 ms |
28500 KB |
Output is correct |
6 |
Correct |
19 ms |
28492 KB |
Output is correct |
7 |
Correct |
19 ms |
28492 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
19 ms |
28508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
28492 KB |
Output is correct |
2 |
Correct |
18 ms |
28492 KB |
Output is correct |
3 |
Correct |
19 ms |
28500 KB |
Output is correct |
4 |
Correct |
20 ms |
28364 KB |
Output is correct |
5 |
Correct |
18 ms |
28500 KB |
Output is correct |
6 |
Correct |
19 ms |
28492 KB |
Output is correct |
7 |
Correct |
19 ms |
28492 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
19 ms |
28508 KB |
Output is correct |
10 |
Correct |
25 ms |
29356 KB |
Output is correct |
11 |
Correct |
25 ms |
29444 KB |
Output is correct |
12 |
Correct |
26 ms |
29900 KB |
Output is correct |
13 |
Correct |
24 ms |
29100 KB |
Output is correct |
14 |
Correct |
23 ms |
29124 KB |
Output is correct |
15 |
Correct |
29 ms |
29484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1425 ms |
161464 KB |
Output is correct |
2 |
Correct |
594 ms |
89020 KB |
Output is correct |
3 |
Correct |
640 ms |
109952 KB |
Output is correct |
4 |
Correct |
825 ms |
127672 KB |
Output is correct |
5 |
Correct |
861 ms |
130776 KB |
Output is correct |
6 |
Correct |
1139 ms |
141532 KB |
Output is correct |
7 |
Correct |
1379 ms |
173164 KB |
Output is correct |
8 |
Correct |
546 ms |
97464 KB |
Output is correct |
9 |
Correct |
546 ms |
108168 KB |
Output is correct |
10 |
Correct |
835 ms |
128268 KB |
Output is correct |
11 |
Correct |
879 ms |
130768 KB |
Output is correct |
12 |
Correct |
1000 ms |
142080 KB |
Output is correct |
13 |
Correct |
470 ms |
86624 KB |
Output is correct |
14 |
Correct |
502 ms |
86656 KB |
Output is correct |
15 |
Correct |
472 ms |
86788 KB |
Output is correct |
16 |
Correct |
479 ms |
86704 KB |
Output is correct |
17 |
Correct |
1309 ms |
171140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
28492 KB |
Output is correct |
2 |
Correct |
18 ms |
28492 KB |
Output is correct |
3 |
Correct |
19 ms |
28500 KB |
Output is correct |
4 |
Correct |
20 ms |
28364 KB |
Output is correct |
5 |
Correct |
18 ms |
28500 KB |
Output is correct |
6 |
Correct |
19 ms |
28492 KB |
Output is correct |
7 |
Correct |
19 ms |
28492 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
19 ms |
28508 KB |
Output is correct |
10 |
Correct |
25 ms |
29356 KB |
Output is correct |
11 |
Correct |
25 ms |
29444 KB |
Output is correct |
12 |
Correct |
26 ms |
29900 KB |
Output is correct |
13 |
Correct |
24 ms |
29100 KB |
Output is correct |
14 |
Correct |
23 ms |
29124 KB |
Output is correct |
15 |
Correct |
29 ms |
29484 KB |
Output is correct |
16 |
Correct |
1425 ms |
161464 KB |
Output is correct |
17 |
Correct |
594 ms |
89020 KB |
Output is correct |
18 |
Correct |
640 ms |
109952 KB |
Output is correct |
19 |
Correct |
825 ms |
127672 KB |
Output is correct |
20 |
Correct |
861 ms |
130776 KB |
Output is correct |
21 |
Correct |
1139 ms |
141532 KB |
Output is correct |
22 |
Correct |
1379 ms |
173164 KB |
Output is correct |
23 |
Correct |
546 ms |
97464 KB |
Output is correct |
24 |
Correct |
546 ms |
108168 KB |
Output is correct |
25 |
Correct |
835 ms |
128268 KB |
Output is correct |
26 |
Correct |
879 ms |
130768 KB |
Output is correct |
27 |
Correct |
1000 ms |
142080 KB |
Output is correct |
28 |
Correct |
470 ms |
86624 KB |
Output is correct |
29 |
Correct |
502 ms |
86656 KB |
Output is correct |
30 |
Correct |
472 ms |
86788 KB |
Output is correct |
31 |
Correct |
479 ms |
86704 KB |
Output is correct |
32 |
Correct |
1309 ms |
171140 KB |
Output is correct |
33 |
Correct |
1079 ms |
114868 KB |
Output is correct |
34 |
Correct |
297 ms |
60356 KB |
Output is correct |
35 |
Correct |
858 ms |
100920 KB |
Output is correct |
36 |
Correct |
1029 ms |
121944 KB |
Output is correct |
37 |
Correct |
894 ms |
102576 KB |
Output is correct |
38 |
Correct |
1046 ms |
116380 KB |
Output is correct |
39 |
Correct |
559 ms |
84408 KB |
Output is correct |
40 |
Correct |
879 ms |
104636 KB |
Output is correct |
41 |
Correct |
881 ms |
104540 KB |
Output is correct |
42 |
Correct |
979 ms |
120492 KB |
Output is correct |
43 |
Correct |
814 ms |
97784 KB |
Output is correct |
44 |
Correct |
836 ms |
102860 KB |
Output is correct |
45 |
Correct |
457 ms |
81260 KB |
Output is correct |
46 |
Correct |
487 ms |
82616 KB |
Output is correct |
47 |
Correct |
460 ms |
86968 KB |
Output is correct |
48 |
Correct |
455 ms |
86936 KB |
Output is correct |
49 |
Correct |
551 ms |
86836 KB |
Output is correct |
50 |
Correct |
521 ms |
86660 KB |
Output is correct |
51 |
Correct |
824 ms |
105908 KB |
Output is correct |
52 |
Correct |
837 ms |
105900 KB |
Output is correct |