# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1085222 |
2024-09-07T17:21:01 Z |
ASN49K |
Werewolf (IOI18_werewolf) |
C++14 |
|
2226 ms |
256336 KB |
#include "werewolf.h"
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
using namespace std;
struct query
{
int x,y,val_l,val_r,ind,pointer1,pointer2;
};
const int N=200'000,UNSET=-1;
int n,q;
vector<int>adj[N];
vector<query>querys;
set<int>aint[2*N+1];
int lsb(int x,int y)
{
return x&(-x);
}
void add(int x,int y)
{
for(int i=x+n;i>0;i>>=1)
{
aint[i].insert(y);
}
}
bool is_point(int x1,int x2,int y1,int y2)
{
x1+=n;
x2+=n;
for(;x1<=x2;x1>>=1,x2>>=1)
{
if(x1&1)
{
if(aint[x1].lower_bound(y1)!=aint[x1].upper_bound(y2))
{
return true;
}
x1++;
}
if(!(x2&1))
{
if(aint[x2].lower_bound(y1)!=aint[x2].upper_bound(y2))
{
return true;
}
x2--;
}
}
return false;
}
struct Dsu
{
int size_dsu,acm;
vector<int>t,l_child,r_child,l,r,poz;
void init(int n)
{
this->size_dsu=n;
this->acm=-1;
t.resize(2*n);
poz.resize(n);
l_child=r_child=l=r=vector<int>(2*n,0);
iota(all(t) , 0);
}
int root(int x)
{
if(t[x]!=x)
{
t[x]=root(t[x]);
}
return t[x];
}
void unite(int x,int y)
{
x=root(x);
y=root(y);
if(x!=y)
{
l_child[size_dsu]=x;
r_child[size_dsu]=y;
t[x]=t[y]=size_dsu++;
}
}
void dfs(int nod)
{
if(nod<n)
{
//cout<<"da";
l[nod]=r[nod]=++acm;
poz[nod]=acm;
}
else
{
dfs(l_child[nod]);
dfs(r_child[nod]);
l[nod]=l[l_child[nod]];
r[nod]=r[r_child[nod]];
}
}
};
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,std::vector<int> S, std::vector<int> E,std::vector<int> L, std::vector<int> R)
{
n=N;
q=(int)L.size();
vector<int>rez(q);
for(int i=0;i<(int)X.size();i++)
{
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
querys.resize(q);
querys.shrink_to_fit();
for(int i=0;i<q;i++) {
assert(S[i] >= L[i] && E[i] <= R[i]);
querys[i] = {S[i], E[i], L[i], R[i], i, UNSET ,UNSET};
}
Dsu dsu[2];
dsu[0].init(n);
sort(all(querys),[&](const query& a,const query& b){
return a.val_l>b.val_l;
});
int last=n;
for(auto &c:querys)
{
while(last>c.val_l)
{
last--;
for(auto &v:adj[last])
{
if(last<v)
{
dsu[0].unite(v,last);
}
}
}
c.pointer1=dsu[0].root(c.x);
}
while(last>-1)
{
last--;
for(auto &v:adj[last])
{
if(last<v)
{
dsu[0].unite(v,last);
}
}
}
dsu[1].init(n);
sort(all(querys),[&](const query& a,const query& b){
return a.val_r<b.val_r;
});
last=-1;
for(auto &c:querys)
{
while(last<c.val_r)
{
last++;
for(auto &v:adj[last])
{
if(v<last)
{
dsu[1].unite(v,last);
}
}
}
c.pointer2=dsu[1].root(c.y);
}
while(last<n-1)
{
last++;
for(auto &v:adj[last])
{
if(v<last)
{
dsu[1].unite(v,last);
}
}
}
dsu[0].dfs(2*n-2);
dsu[1].dfs(2*n-2);
for(int i=0;i<n;i++)
{
add(dsu[0].poz[i] , dsu[1].poz[i]);
//cout<<dsu[0].poz[i]<<' '<<dsu[1].poz[i]<<'\n';
}
for(auto &c:querys)
{
//l in loc de r
rez[c.ind]=is_point(dsu[0].l[c.pointer1],dsu[0].r[c.pointer1],dsu[1].l[c.pointer2],dsu[1].r[c.pointer2]);
}
return rez;
}
/*
6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
24152 KB |
Output is correct |
9 |
Correct |
10 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
24152 KB |
Output is correct |
9 |
Correct |
10 ms |
23900 KB |
Output is correct |
10 |
Correct |
23 ms |
26204 KB |
Output is correct |
11 |
Correct |
19 ms |
26204 KB |
Output is correct |
12 |
Correct |
18 ms |
26204 KB |
Output is correct |
13 |
Correct |
19 ms |
26460 KB |
Output is correct |
14 |
Correct |
18 ms |
26460 KB |
Output is correct |
15 |
Correct |
21 ms |
26504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1604 ms |
245252 KB |
Output is correct |
2 |
Correct |
986 ms |
249168 KB |
Output is correct |
3 |
Correct |
923 ms |
247708 KB |
Output is correct |
4 |
Correct |
1037 ms |
246984 KB |
Output is correct |
5 |
Correct |
1114 ms |
247120 KB |
Output is correct |
6 |
Correct |
1352 ms |
246864 KB |
Output is correct |
7 |
Correct |
1569 ms |
246920 KB |
Output is correct |
8 |
Correct |
912 ms |
248916 KB |
Output is correct |
9 |
Correct |
900 ms |
247636 KB |
Output is correct |
10 |
Correct |
1161 ms |
247120 KB |
Output is correct |
11 |
Correct |
1206 ms |
247360 KB |
Output is correct |
12 |
Correct |
1242 ms |
247104 KB |
Output is correct |
13 |
Correct |
1075 ms |
249020 KB |
Output is correct |
14 |
Correct |
1050 ms |
248912 KB |
Output is correct |
15 |
Correct |
1082 ms |
248916 KB |
Output is correct |
16 |
Correct |
1042 ms |
249024 KB |
Output is correct |
17 |
Correct |
1578 ms |
246972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
24152 KB |
Output is correct |
9 |
Correct |
10 ms |
23900 KB |
Output is correct |
10 |
Correct |
23 ms |
26204 KB |
Output is correct |
11 |
Correct |
19 ms |
26204 KB |
Output is correct |
12 |
Correct |
18 ms |
26204 KB |
Output is correct |
13 |
Correct |
19 ms |
26460 KB |
Output is correct |
14 |
Correct |
18 ms |
26460 KB |
Output is correct |
15 |
Correct |
21 ms |
26504 KB |
Output is correct |
16 |
Correct |
1604 ms |
245252 KB |
Output is correct |
17 |
Correct |
986 ms |
249168 KB |
Output is correct |
18 |
Correct |
923 ms |
247708 KB |
Output is correct |
19 |
Correct |
1037 ms |
246984 KB |
Output is correct |
20 |
Correct |
1114 ms |
247120 KB |
Output is correct |
21 |
Correct |
1352 ms |
246864 KB |
Output is correct |
22 |
Correct |
1569 ms |
246920 KB |
Output is correct |
23 |
Correct |
912 ms |
248916 KB |
Output is correct |
24 |
Correct |
900 ms |
247636 KB |
Output is correct |
25 |
Correct |
1161 ms |
247120 KB |
Output is correct |
26 |
Correct |
1206 ms |
247360 KB |
Output is correct |
27 |
Correct |
1242 ms |
247104 KB |
Output is correct |
28 |
Correct |
1075 ms |
249020 KB |
Output is correct |
29 |
Correct |
1050 ms |
248912 KB |
Output is correct |
30 |
Correct |
1082 ms |
248916 KB |
Output is correct |
31 |
Correct |
1042 ms |
249024 KB |
Output is correct |
32 |
Correct |
1578 ms |
246972 KB |
Output is correct |
33 |
Correct |
2099 ms |
247568 KB |
Output is correct |
34 |
Correct |
190 ms |
60888 KB |
Output is correct |
35 |
Correct |
2044 ms |
249544 KB |
Output is correct |
36 |
Correct |
2101 ms |
247468 KB |
Output is correct |
37 |
Correct |
2145 ms |
249004 KB |
Output is correct |
38 |
Correct |
2226 ms |
247704 KB |
Output is correct |
39 |
Correct |
1743 ms |
251288 KB |
Output is correct |
40 |
Correct |
1556 ms |
256336 KB |
Output is correct |
41 |
Correct |
1973 ms |
248660 KB |
Output is correct |
42 |
Correct |
1957 ms |
247384 KB |
Output is correct |
43 |
Correct |
1625 ms |
252828 KB |
Output is correct |
44 |
Correct |
2109 ms |
248960 KB |
Output is correct |
45 |
Correct |
1792 ms |
251808 KB |
Output is correct |
46 |
Correct |
1800 ms |
251288 KB |
Output is correct |
47 |
Correct |
1027 ms |
249168 KB |
Output is correct |
48 |
Correct |
1079 ms |
249168 KB |
Output is correct |
49 |
Correct |
1029 ms |
249108 KB |
Output is correct |
50 |
Correct |
1054 ms |
248912 KB |
Output is correct |
51 |
Correct |
1653 ms |
256080 KB |
Output is correct |
52 |
Correct |
1659 ms |
256156 KB |
Output is correct |