/**
* Author : Nguyen Tuan Vu
* Created : 25.01.2023
**/
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1ll)<<(x))
#define BIT(x, i) (((x)>>(i))&(1))
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define db(val) "["#val" = "<<(val)<<"] "
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
using namespace std;
mt19937 jdg(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {return l + jdg() % (r - l + 1);}
const int MAXN = 4e5 + 5;
int n, m, nquery;
pair <int, int> edges[MAXN];
vector <int> adj[MAXN];
struct QUERY {
int s, t, l, r;
// constraints :
// For each query i : 0 <= i < Q
// 0 <= l(i) <= s(i) <= n - 1
// 0 <= e(i) <= r(i) <= n - 1
// s(i) != e(i)
// l(i) <= r(i)
QUERY() {}
QUERY(int s, int t, int l, int r) {
this->s = s;
this->t = t;
this->l = l;
this->r = r;
}
} q[MAXN];
namespace sub2 {
int dd[MAXN][2], cur;
void dfs(int u, int trans, int i) {
if (dd[u][trans] == cur) return;
//cout << u << ' ' << trans << '\n';
dd[u][trans] = cur;
if (dd[q[i].t][1] == cur) return;
for (auto v : adj[u]) {
if (trans == 0) {
if (q[i].l <= v && v <= q[i].r) {
dfs(v, 0, i);
dfs(v, 1, i);
}
else if (v > q[i].r) {
dfs(v, 0, i);
}
}
else {
if (q[i].l <= v && v <= q[i].r) {
dfs(v, 1, i);
}
else if (v < q[i].l) {
dfs(v, 1, i);
}
}
}
}
vector <int> solve() {
vector <int> tmp;
FOR(i, 1, nquery) {
++cur;
dfs(q[i].s, 0, i);
if (q[i].l <= q[i].s && q[i].s <= q[i].r) dfs(q[i].s, 1, i);
if (dd[q[i].t][1] == cur) tmp.push_back(1);
else tmp.push_back(0);
}
return tmp;
}
};
vector <int> check_validity(int N, vector <int> X, vector <int> Y, vector <int> S, vector <int> T, vector <int> L, vector <int> R) {
n = N; m = X.size(); nquery = S.size();
REP(i, m) {
edges[i + 1] = make_pair(X[i], Y[i]);
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
REP(i, nquery) q[i + 1] = QUERY(S[i], T[i], L[i], R[i]);
if (n <= 3000 && m <= 6000 && nquery <= 3000) return sub2::solve();
return vector <int> (nquery, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
152 ms |
10228 KB |
Output is correct |
11 |
Correct |
114 ms |
10164 KB |
Output is correct |
12 |
Correct |
19 ms |
10372 KB |
Output is correct |
13 |
Correct |
132 ms |
10352 KB |
Output is correct |
14 |
Correct |
99 ms |
10164 KB |
Output is correct |
15 |
Correct |
264 ms |
10344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
30796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
152 ms |
10228 KB |
Output is correct |
11 |
Correct |
114 ms |
10164 KB |
Output is correct |
12 |
Correct |
19 ms |
10372 KB |
Output is correct |
13 |
Correct |
132 ms |
10352 KB |
Output is correct |
14 |
Correct |
99 ms |
10164 KB |
Output is correct |
15 |
Correct |
264 ms |
10344 KB |
Output is correct |
16 |
Incorrect |
191 ms |
30796 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |