# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
816828 |
2023-08-09T06:54:26 Z |
ttamx |
Werewolf (IOI18_werewolf) |
C++14 |
|
932 ms |
122032 KB |
#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p2;
const int N=2e5+5;
const int M=4e5+5;
const int K=(1<<19)+5;
int n,m,q;
vector<int> adj[N];
int s[N],e[N],l[N],r[N];
vector<int> ql[N],qr[N];
int pl[N],pr[N];
p2 ranl[N],ranr[N];
int posx[N],posy[N];
vector<int> num[N];
struct dsu_t{
int p[M];
int in[M],out[M],pos[M];
vector<p2> node;
void init(){
for(int i=0;i<2*n;i++){
p[i]=i;
}
node=vector<p2>(n,p2(-1,-1));
}
int fp(int u){
if(u==p[u])return u;
return p[u]=fp(p[u]);
}
void uni(int u,int v){
u=fp(u),v=fp(v);
if(u==v)return;
int np=node.size();
p[u]=p[v]=np;
node.emplace_back(u,v);
}
void dfs(int u,int &t){
if(u<n){
in[u]=out[u]=++t;
pos[t]=u;
return;
}
auto [l,r]=node[u];
dfs(l,t);
dfs(r,t);
in[u]=min(in[l],in[r]);
out[u]=max(out[l],out[r]);
}
void dfs(){
int t=0;
dfs(node.size()-1,t);
}
}dsu;
struct segtree{
vector<int> t[K];
void build(int l,int r,int i){
if(l==r)return void(t[i]=num[l]);
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
int x=0,y=0;
while(x<t[i*2].size()||y<t[i*2+1].size()){
if(x==t[i*2].size()||(y<t[i*2+1].size()&&t[i*2][x]>t[i*2+1][y]))t[i].emplace_back(t[i*2+1][y++]);
else t[i].emplace_back(t[i*2][x++]);
}
}
void build(){
build(1,n,1);
}
int query(int l,int r,int i,int x,int y,int a,int b){
if(y<l||r<x)return 0;
if(x<=l&&r<=y)return upper_bound(t[i].begin(),t[i].end(),b)-lower_bound(t[i].begin(),t[i].end(),a);
int m=(l+r)/2;
return query(l,m,i*2,x,y,a,b)+query(m+1,r,i*2+1,x,y,a,b);
}
int query(int x,int y,int a,int b){
return query(1,n,1,x,y,a,b);
}
}seg;
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;
m=X.size();
q=S.size();
for(int i=0;i<m;i++){
int u=X[i],v=Y[i];
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
for(int i=0;i<q;i++){
s[i]=S[i];
e[i]=E[i];
l[i]=L[i];
r[i]=R[i];
ql[l[i]].emplace_back(i);
qr[r[i]].emplace_back(i);
}
dsu.init();
for(int u=n-1;u>=0;u--){
for(auto v:adj[u]){
if(v<u)continue;
dsu.uni(u,v);
}
for(auto i:ql[u]){
pl[i]=dsu.fp(s[i]);
}
}
dsu.dfs();
for(int i=0;i<n;i++)posx[i]=dsu.in[i];
for(int i=0;i<q;i++){
int p=pl[i];
ranl[i]=p2(dsu.in[p],dsu.out[p]);
}
dsu.init();
for(int u=0;u<n;u++){
for(auto v:adj[u]){
if(v>u)continue;
dsu.uni(u,v);
}
for(auto i:qr[u]){
pr[i]=dsu.fp(e[i]);
}
}
dsu.dfs();
for(int i=0;i<n;i++)posy[i]=dsu.in[i];
for(int i=0;i<q;i++){
int p=pr[i];
ranr[i]=p2(dsu.in[p],dsu.out[p]);
}
for(int i=0;i<n;i++)num[posx[i]].emplace_back(posy[i]);
for(int i=1;i<=n;i++)sort(num[i].begin(),num[i].end());
seg.build();
vector<int> ans(q);
for(int i=0;i<q;i++){
auto [x,y]=ranl[i];
auto [a,b]=ranr[i];
ans[i]=seg.query(x,y,a,b)>0;
}
return ans;
}
Compilation message
werewolf.cpp: In member function 'void dsu_t::dfs(int, int&)':
werewolf.cpp:48:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | auto [l,r]=node[u];
| ^
werewolf.cpp: In member function 'void segtree::build(int, int, int)':
werewolf.cpp:68:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while(x<t[i*2].size()||y<t[i*2+1].size()){
| ~^~~~~~~~~~~~~~
werewolf.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while(x<t[i*2].size()||y<t[i*2+1].size()){
| ~^~~~~~~~~~~~~~~~
werewolf.cpp:69:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | if(x==t[i*2].size()||(y<t[i*2+1].size()&&t[i*2][x]>t[i*2+1][y]))t[i].emplace_back(t[i*2+1][y++]);
| ~^~~~~~~~~~~~~~~
werewolf.cpp:69:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | if(x==t[i*2].size()||(y<t[i*2+1].size()&&t[i*2][x]>t[i*2+1][y]))t[i].emplace_back(t[i*2+1][y++]);
| ~^~~~~~~~~~~~~~~~
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:141:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
141 | auto [x,y]=ranl[i];
| ^
werewolf.cpp:142:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
142 | auto [a,b]=ranr[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31444 KB |
Output is correct |
2 |
Correct |
14 ms |
31388 KB |
Output is correct |
3 |
Correct |
14 ms |
31428 KB |
Output is correct |
4 |
Correct |
14 ms |
31492 KB |
Output is correct |
5 |
Correct |
15 ms |
31512 KB |
Output is correct |
6 |
Correct |
15 ms |
31420 KB |
Output is correct |
7 |
Correct |
17 ms |
31516 KB |
Output is correct |
8 |
Correct |
16 ms |
31444 KB |
Output is correct |
9 |
Correct |
18 ms |
31420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31444 KB |
Output is correct |
2 |
Correct |
14 ms |
31388 KB |
Output is correct |
3 |
Correct |
14 ms |
31428 KB |
Output is correct |
4 |
Correct |
14 ms |
31492 KB |
Output is correct |
5 |
Correct |
15 ms |
31512 KB |
Output is correct |
6 |
Correct |
15 ms |
31420 KB |
Output is correct |
7 |
Correct |
17 ms |
31516 KB |
Output is correct |
8 |
Correct |
16 ms |
31444 KB |
Output is correct |
9 |
Correct |
18 ms |
31420 KB |
Output is correct |
10 |
Correct |
20 ms |
32676 KB |
Output is correct |
11 |
Correct |
20 ms |
32592 KB |
Output is correct |
12 |
Correct |
19 ms |
32544 KB |
Output is correct |
13 |
Correct |
19 ms |
32708 KB |
Output is correct |
14 |
Correct |
19 ms |
32724 KB |
Output is correct |
15 |
Correct |
20 ms |
32700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
532 ms |
106048 KB |
Output is correct |
2 |
Correct |
661 ms |
110956 KB |
Output is correct |
3 |
Correct |
577 ms |
108880 KB |
Output is correct |
4 |
Correct |
508 ms |
108068 KB |
Output is correct |
5 |
Correct |
553 ms |
108060 KB |
Output is correct |
6 |
Correct |
548 ms |
107920 KB |
Output is correct |
7 |
Correct |
452 ms |
105576 KB |
Output is correct |
8 |
Correct |
634 ms |
111012 KB |
Output is correct |
9 |
Correct |
395 ms |
107816 KB |
Output is correct |
10 |
Correct |
490 ms |
106788 KB |
Output is correct |
11 |
Correct |
598 ms |
106956 KB |
Output is correct |
12 |
Correct |
390 ms |
107592 KB |
Output is correct |
13 |
Correct |
678 ms |
111592 KB |
Output is correct |
14 |
Correct |
559 ms |
111508 KB |
Output is correct |
15 |
Correct |
535 ms |
111592 KB |
Output is correct |
16 |
Correct |
553 ms |
111592 KB |
Output is correct |
17 |
Correct |
419 ms |
105596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31444 KB |
Output is correct |
2 |
Correct |
14 ms |
31388 KB |
Output is correct |
3 |
Correct |
14 ms |
31428 KB |
Output is correct |
4 |
Correct |
14 ms |
31492 KB |
Output is correct |
5 |
Correct |
15 ms |
31512 KB |
Output is correct |
6 |
Correct |
15 ms |
31420 KB |
Output is correct |
7 |
Correct |
17 ms |
31516 KB |
Output is correct |
8 |
Correct |
16 ms |
31444 KB |
Output is correct |
9 |
Correct |
18 ms |
31420 KB |
Output is correct |
10 |
Correct |
20 ms |
32676 KB |
Output is correct |
11 |
Correct |
20 ms |
32592 KB |
Output is correct |
12 |
Correct |
19 ms |
32544 KB |
Output is correct |
13 |
Correct |
19 ms |
32708 KB |
Output is correct |
14 |
Correct |
19 ms |
32724 KB |
Output is correct |
15 |
Correct |
20 ms |
32700 KB |
Output is correct |
16 |
Correct |
532 ms |
106048 KB |
Output is correct |
17 |
Correct |
661 ms |
110956 KB |
Output is correct |
18 |
Correct |
577 ms |
108880 KB |
Output is correct |
19 |
Correct |
508 ms |
108068 KB |
Output is correct |
20 |
Correct |
553 ms |
108060 KB |
Output is correct |
21 |
Correct |
548 ms |
107920 KB |
Output is correct |
22 |
Correct |
452 ms |
105576 KB |
Output is correct |
23 |
Correct |
634 ms |
111012 KB |
Output is correct |
24 |
Correct |
395 ms |
107816 KB |
Output is correct |
25 |
Correct |
490 ms |
106788 KB |
Output is correct |
26 |
Correct |
598 ms |
106956 KB |
Output is correct |
27 |
Correct |
390 ms |
107592 KB |
Output is correct |
28 |
Correct |
678 ms |
111592 KB |
Output is correct |
29 |
Correct |
559 ms |
111508 KB |
Output is correct |
30 |
Correct |
535 ms |
111592 KB |
Output is correct |
31 |
Correct |
553 ms |
111592 KB |
Output is correct |
32 |
Correct |
419 ms |
105596 KB |
Output is correct |
33 |
Correct |
674 ms |
115512 KB |
Output is correct |
34 |
Correct |
207 ms |
72508 KB |
Output is correct |
35 |
Correct |
813 ms |
117980 KB |
Output is correct |
36 |
Correct |
611 ms |
115088 KB |
Output is correct |
37 |
Correct |
845 ms |
117240 KB |
Output is correct |
38 |
Correct |
628 ms |
115596 KB |
Output is correct |
39 |
Correct |
493 ms |
122032 KB |
Output is correct |
40 |
Correct |
503 ms |
121256 KB |
Output is correct |
41 |
Correct |
678 ms |
116760 KB |
Output is correct |
42 |
Correct |
453 ms |
113864 KB |
Output is correct |
43 |
Correct |
932 ms |
121404 KB |
Output is correct |
44 |
Correct |
762 ms |
117284 KB |
Output is correct |
45 |
Correct |
555 ms |
121208 KB |
Output is correct |
46 |
Correct |
726 ms |
121000 KB |
Output is correct |
47 |
Correct |
521 ms |
118380 KB |
Output is correct |
48 |
Correct |
485 ms |
118152 KB |
Output is correct |
49 |
Correct |
514 ms |
118292 KB |
Output is correct |
50 |
Correct |
492 ms |
118032 KB |
Output is correct |
51 |
Correct |
453 ms |
119896 KB |
Output is correct |
52 |
Correct |
452 ms |
119880 KB |
Output is correct |