#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7, LG=20;
vi V[LIM], pytania[LIM], dodaj[LIM];
vector<pair<int,int>>kraw;
set<int>zbior[LIM];
int Fl[LIM], pocz[LIM], kon[LIM], nxt[LIM][LG], lpre;
int Fr[LIM], ile[LIM];
int n, m;
int fndl(int x) {
if(Fl[x]==x) return x;
return Fl[x]=fndl(Fl[x]);
}
void unil(int a, int b) {
a=fndl(a);
b=fndl(b);
if(a==b) return;
Fl[b]=a;
V[a].pb(b);
}
void DFS(int x) {
++lpre;
pocz[x]=lpre;
for(auto i : V[x]) {
nxt[i][0]=x;
DFS(i);
}
kon[x]=lpre;
}
int poddrzewo(int v, int l) {
for(int i=LG-1; i>=0; --i) if(nxt[v][i]>=l) v=nxt[v][i];
return v;
}
int fndr(int x) {
if(Fr[x]==x) return x;
return fndr(Fr[x]);
}
void unir(int a, int b) {
a=fndr(a);
b=fndr(b);
if(a==b) return;
if(ile[a]<ile[b]) swap(a, b);
for(auto i : zbior[b]) zbior[a].insert(i);
zbior[b].clear();
ile[a]+=ile[b];
Fr[b]=a;
}
vi check_validity(int N, vi X, vi Y, vi S, vi E, vi L, vi R) {
n=N;
m=X.size();
rep(i, n) Fl[i]=i;
rep(i, m) {
if(X[i]>Y[i]) swap(X[i], Y[i]);
kraw.pb({X[i], Y[i]});
}
sort(all(kraw));
reverse(all(kraw));
for(auto i : kraw) unil(i.st, i.nd);
DFS(0);
for(int j=1; j<LG; ++j) {
rep(i, n) nxt[i][j]=nxt[nxt[i][j-1]][j-1];
}
rep(i, S.size()) pytania[R[i]].pb(i);
vi ans(S.size());
rep(i, n) {
Fr[i]=i;
ile[i]=1;
zbior[i].insert(pocz[i]);
}
rep(i, m) dodaj[kraw[i].nd].pb(kraw[i].st);
rep(i, n) {
for(auto j : dodaj[i]) unir(i, j);
for(auto j : pytania[i]) {
int p=poddrzewo(S[j], L[j]);
int x=fndr(E[j]);
auto it=zbior[x].lower_bound(pocz[p]);
if(it==zbior[x].end()) continue;
auto a=*it;
if(a<=kon[p]) ans[j]=1;
}
}
return ans;
}
Compilation message
werewolf.cpp: In function 'vi check_validity(int, vi, vi, vi, vi, vi, vi)':
werewolf.cpp:7:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
werewolf.cpp:72:2: note: in expansion of macro 'rep'
72 | rep(i, S.size()) pytania[R[i]].pb(i);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23752 KB |
Output is correct |
2 |
Correct |
15 ms |
23800 KB |
Output is correct |
3 |
Correct |
13 ms |
23720 KB |
Output is correct |
4 |
Correct |
13 ms |
23784 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
12 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23760 KB |
Output is correct |
8 |
Correct |
14 ms |
23760 KB |
Output is correct |
9 |
Correct |
15 ms |
23760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23752 KB |
Output is correct |
2 |
Correct |
15 ms |
23800 KB |
Output is correct |
3 |
Correct |
13 ms |
23720 KB |
Output is correct |
4 |
Correct |
13 ms |
23784 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
12 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23760 KB |
Output is correct |
8 |
Correct |
14 ms |
23760 KB |
Output is correct |
9 |
Correct |
15 ms |
23760 KB |
Output is correct |
10 |
Correct |
22 ms |
24720 KB |
Output is correct |
11 |
Correct |
22 ms |
24692 KB |
Output is correct |
12 |
Correct |
22 ms |
24736 KB |
Output is correct |
13 |
Correct |
18 ms |
24708 KB |
Output is correct |
14 |
Correct |
19 ms |
24784 KB |
Output is correct |
15 |
Correct |
18 ms |
24932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
791 ms |
83608 KB |
Output is correct |
2 |
Correct |
506 ms |
80276 KB |
Output is correct |
3 |
Correct |
459 ms |
79484 KB |
Output is correct |
4 |
Correct |
511 ms |
79396 KB |
Output is correct |
5 |
Correct |
574 ms |
79524 KB |
Output is correct |
6 |
Correct |
641 ms |
80028 KB |
Output is correct |
7 |
Correct |
726 ms |
81712 KB |
Output is correct |
8 |
Correct |
457 ms |
80240 KB |
Output is correct |
9 |
Correct |
419 ms |
80176 KB |
Output is correct |
10 |
Correct |
427 ms |
77364 KB |
Output is correct |
11 |
Correct |
417 ms |
77460 KB |
Output is correct |
12 |
Correct |
587 ms |
81064 KB |
Output is correct |
13 |
Correct |
556 ms |
92656 KB |
Output is correct |
14 |
Correct |
647 ms |
92588 KB |
Output is correct |
15 |
Correct |
569 ms |
92428 KB |
Output is correct |
16 |
Correct |
561 ms |
92288 KB |
Output is correct |
17 |
Correct |
747 ms |
81192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23752 KB |
Output is correct |
2 |
Correct |
15 ms |
23800 KB |
Output is correct |
3 |
Correct |
13 ms |
23720 KB |
Output is correct |
4 |
Correct |
13 ms |
23784 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
12 ms |
23720 KB |
Output is correct |
7 |
Correct |
12 ms |
23760 KB |
Output is correct |
8 |
Correct |
14 ms |
23760 KB |
Output is correct |
9 |
Correct |
15 ms |
23760 KB |
Output is correct |
10 |
Correct |
22 ms |
24720 KB |
Output is correct |
11 |
Correct |
22 ms |
24692 KB |
Output is correct |
12 |
Correct |
22 ms |
24736 KB |
Output is correct |
13 |
Correct |
18 ms |
24708 KB |
Output is correct |
14 |
Correct |
19 ms |
24784 KB |
Output is correct |
15 |
Correct |
18 ms |
24932 KB |
Output is correct |
16 |
Correct |
791 ms |
83608 KB |
Output is correct |
17 |
Correct |
506 ms |
80276 KB |
Output is correct |
18 |
Correct |
459 ms |
79484 KB |
Output is correct |
19 |
Correct |
511 ms |
79396 KB |
Output is correct |
20 |
Correct |
574 ms |
79524 KB |
Output is correct |
21 |
Correct |
641 ms |
80028 KB |
Output is correct |
22 |
Correct |
726 ms |
81712 KB |
Output is correct |
23 |
Correct |
457 ms |
80240 KB |
Output is correct |
24 |
Correct |
419 ms |
80176 KB |
Output is correct |
25 |
Correct |
427 ms |
77364 KB |
Output is correct |
26 |
Correct |
417 ms |
77460 KB |
Output is correct |
27 |
Correct |
587 ms |
81064 KB |
Output is correct |
28 |
Correct |
556 ms |
92656 KB |
Output is correct |
29 |
Correct |
647 ms |
92588 KB |
Output is correct |
30 |
Correct |
569 ms |
92428 KB |
Output is correct |
31 |
Correct |
561 ms |
92288 KB |
Output is correct |
32 |
Correct |
747 ms |
81192 KB |
Output is correct |
33 |
Correct |
720 ms |
85676 KB |
Output is correct |
34 |
Correct |
309 ms |
55508 KB |
Output is correct |
35 |
Correct |
749 ms |
87756 KB |
Output is correct |
36 |
Correct |
725 ms |
85460 KB |
Output is correct |
37 |
Correct |
747 ms |
86628 KB |
Output is correct |
38 |
Correct |
693 ms |
85992 KB |
Output is correct |
39 |
Correct |
548 ms |
85644 KB |
Output is correct |
40 |
Correct |
724 ms |
98252 KB |
Output is correct |
41 |
Correct |
588 ms |
86224 KB |
Output is correct |
42 |
Correct |
614 ms |
86540 KB |
Output is correct |
43 |
Correct |
751 ms |
93600 KB |
Output is correct |
44 |
Correct |
665 ms |
86792 KB |
Output is correct |
45 |
Correct |
544 ms |
87348 KB |
Output is correct |
46 |
Correct |
555 ms |
86632 KB |
Output is correct |
47 |
Correct |
576 ms |
98112 KB |
Output is correct |
48 |
Correct |
560 ms |
97880 KB |
Output is correct |
49 |
Correct |
552 ms |
98064 KB |
Output is correct |
50 |
Correct |
568 ms |
97960 KB |
Output is correct |
51 |
Correct |
703 ms |
97740 KB |
Output is correct |
52 |
Correct |
698 ms |
97824 KB |
Output is correct |