#include "werewolf.h"
//Arayi
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
const int N = 1e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 238;
const ld e = 1e-13;
int n, q;
vii g[N], l1[N], r1[N], pat, g1[N];
int p[N], sz[N], cll[N], clr[N], col[N];
set<int> fp[N];
int gp(int x)
{
if (p[x] == x) return x;
return p[x] = gp(p[x]);
}
void dfs(int v, int l, int r)
{
cll[v] = l;
clr[v] = r;
if (v < n) return;
int sm = 0;
for (auto p : g1[v])
{
dfs(p, l + sm, l + sm + sz[p] - 1);
sm += sz[p];
}
}
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;
q = (int)S.size();
pat.resize(q);
for (int i = 0; i < q; i++)
{
l1[L[i]].ad(i);
r1[R[i]].ad(i);
}
for (int i = 0; i < (int)X.size(); i++)
{
g[X[i]].ad(Y[i]);
g[Y[i]].ad(X[i]);
}
for (int i = 0; i < N; i++) p[i] = i, sz[i] = 1;
int i1 = n;
for (int i = n - 1; i >= 0; i--)
{
p[i1] = i1;
sz[i1] = sz[i];
for (auto p1 : g[i])
{
if (p1 > i && gp(p1) != i1)
{
int y = gp(p1);
sz[i1] += sz[y];
p[y] = i1;
g1[i1].ad(y);
}
}
g1[i1].ad(i);
p[i] = i1;
i1++;
for (auto p1 : l1[i])
col[p1] = gp(S[p1]);
}
dfs(i1 - 1, 0, n - 1);
for (int i = 0; i < n; i++) p[i] = i, fp[i].insert(cll[i]);
for (int i = 0; i < n; i++)
{
int mx = 1, i1 = i;
for (auto p1 : g[i])
{
if (p1 < i)
{
int y = gp(p1);
if ((int)fp[y].size() > mx)
{
mx = (int)fp[y].size();
i1 = y;
}
}
}
p[i] = i1;
fp[i1].insert(cll[i]);
for (auto p1 : g[i])
{
if (p1 < i && gp(p1) != i1)
{
int y = gp(p1);
p[y] = i1;
for (auto ii = fp[y].begin(); ii != fp[y].end(); ++ii)
fp[i1].insert(*ii);
}
}
for (auto p1 : r1[i])
{
int x = gp(E[p1]);
int l = cll[col[p1]], r = clr[col[p1]];
if (fp[x].lower_bound(l) != fp[x].end() && *fp[x].lower_bound(l) <= r)
{
pat[p1] = 1;
}
else
{
pat[p1] = 0;
}
}
}
return pat;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
141304 KB |
Output is correct |
2 |
Correct |
76 ms |
141304 KB |
Output is correct |
3 |
Correct |
77 ms |
141304 KB |
Output is correct |
4 |
Correct |
78 ms |
141304 KB |
Output is correct |
5 |
Correct |
81 ms |
141432 KB |
Output is correct |
6 |
Correct |
81 ms |
141304 KB |
Output is correct |
7 |
Correct |
81 ms |
141304 KB |
Output is correct |
8 |
Correct |
81 ms |
141304 KB |
Output is correct |
9 |
Correct |
78 ms |
141340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
141304 KB |
Output is correct |
2 |
Correct |
76 ms |
141304 KB |
Output is correct |
3 |
Correct |
77 ms |
141304 KB |
Output is correct |
4 |
Correct |
78 ms |
141304 KB |
Output is correct |
5 |
Correct |
81 ms |
141432 KB |
Output is correct |
6 |
Correct |
81 ms |
141304 KB |
Output is correct |
7 |
Correct |
81 ms |
141304 KB |
Output is correct |
8 |
Correct |
81 ms |
141304 KB |
Output is correct |
9 |
Correct |
78 ms |
141340 KB |
Output is correct |
10 |
Correct |
85 ms |
142604 KB |
Output is correct |
11 |
Correct |
84 ms |
142332 KB |
Output is correct |
12 |
Correct |
84 ms |
142548 KB |
Output is correct |
13 |
Correct |
85 ms |
142200 KB |
Output is correct |
14 |
Correct |
83 ms |
142200 KB |
Output is correct |
15 |
Correct |
87 ms |
142456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
985 ms |
243680 KB |
Output is correct |
2 |
Correct |
881 ms |
205432 KB |
Output is correct |
3 |
Correct |
796 ms |
210168 KB |
Output is correct |
4 |
Correct |
826 ms |
218488 KB |
Output is correct |
5 |
Correct |
890 ms |
219980 KB |
Output is correct |
6 |
Correct |
948 ms |
226116 KB |
Output is correct |
7 |
Correct |
936 ms |
246392 KB |
Output is correct |
8 |
Correct |
777 ms |
205380 KB |
Output is correct |
9 |
Correct |
736 ms |
209080 KB |
Output is correct |
10 |
Correct |
684 ms |
217208 KB |
Output is correct |
11 |
Correct |
691 ms |
222892 KB |
Output is correct |
12 |
Correct |
835 ms |
231160 KB |
Output is correct |
13 |
Correct |
691 ms |
214776 KB |
Output is correct |
14 |
Correct |
685 ms |
214784 KB |
Output is correct |
15 |
Correct |
664 ms |
214648 KB |
Output is correct |
16 |
Correct |
699 ms |
214732 KB |
Output is correct |
17 |
Correct |
964 ms |
250232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
141304 KB |
Output is correct |
2 |
Correct |
76 ms |
141304 KB |
Output is correct |
3 |
Correct |
77 ms |
141304 KB |
Output is correct |
4 |
Correct |
78 ms |
141304 KB |
Output is correct |
5 |
Correct |
81 ms |
141432 KB |
Output is correct |
6 |
Correct |
81 ms |
141304 KB |
Output is correct |
7 |
Correct |
81 ms |
141304 KB |
Output is correct |
8 |
Correct |
81 ms |
141304 KB |
Output is correct |
9 |
Correct |
78 ms |
141340 KB |
Output is correct |
10 |
Correct |
85 ms |
142604 KB |
Output is correct |
11 |
Correct |
84 ms |
142332 KB |
Output is correct |
12 |
Correct |
84 ms |
142548 KB |
Output is correct |
13 |
Correct |
85 ms |
142200 KB |
Output is correct |
14 |
Correct |
83 ms |
142200 KB |
Output is correct |
15 |
Correct |
87 ms |
142456 KB |
Output is correct |
16 |
Correct |
985 ms |
243680 KB |
Output is correct |
17 |
Correct |
881 ms |
205432 KB |
Output is correct |
18 |
Correct |
796 ms |
210168 KB |
Output is correct |
19 |
Correct |
826 ms |
218488 KB |
Output is correct |
20 |
Correct |
890 ms |
219980 KB |
Output is correct |
21 |
Correct |
948 ms |
226116 KB |
Output is correct |
22 |
Correct |
936 ms |
246392 KB |
Output is correct |
23 |
Correct |
777 ms |
205380 KB |
Output is correct |
24 |
Correct |
736 ms |
209080 KB |
Output is correct |
25 |
Correct |
684 ms |
217208 KB |
Output is correct |
26 |
Correct |
691 ms |
222892 KB |
Output is correct |
27 |
Correct |
835 ms |
231160 KB |
Output is correct |
28 |
Correct |
691 ms |
214776 KB |
Output is correct |
29 |
Correct |
685 ms |
214784 KB |
Output is correct |
30 |
Correct |
664 ms |
214648 KB |
Output is correct |
31 |
Correct |
699 ms |
214732 KB |
Output is correct |
32 |
Correct |
964 ms |
250232 KB |
Output is correct |
33 |
Correct |
943 ms |
219640 KB |
Output is correct |
34 |
Correct |
417 ms |
176504 KB |
Output is correct |
35 |
Correct |
939 ms |
215032 KB |
Output is correct |
36 |
Correct |
912 ms |
224224 KB |
Output is correct |
37 |
Correct |
927 ms |
215012 KB |
Output is correct |
38 |
Correct |
1051 ms |
221196 KB |
Output is correct |
39 |
Correct |
1069 ms |
205760 KB |
Output is correct |
40 |
Correct |
1039 ms |
221556 KB |
Output is correct |
41 |
Correct |
930 ms |
215596 KB |
Output is correct |
42 |
Correct |
872 ms |
222540 KB |
Output is correct |
43 |
Correct |
1148 ms |
218096 KB |
Output is correct |
44 |
Correct |
1040 ms |
215500 KB |
Output is correct |
45 |
Correct |
836 ms |
205340 KB |
Output is correct |
46 |
Correct |
932 ms |
204740 KB |
Output is correct |
47 |
Correct |
785 ms |
214828 KB |
Output is correct |
48 |
Correct |
749 ms |
214776 KB |
Output is correct |
49 |
Correct |
671 ms |
214776 KB |
Output is correct |
50 |
Correct |
670 ms |
214776 KB |
Output is correct |
51 |
Correct |
875 ms |
219516 KB |
Output is correct |
52 |
Correct |
871 ms |
219640 KB |
Output is correct |