# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
420428 |
2021-06-08T11:08:22 Z |
A_D |
Werewolf (IOI18_werewolf) |
C++14 |
|
354 ms |
125748 KB |
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+100;
const int Le=19;
int mn[N][Le];
int mx[N][Le];
vector<int> g[N];
int idx[N];
int n;
int cnt=0;
int a[N];
int lo[N];
void dfs(int u,int p)
{
a[cnt]=u;
idx[u]=cnt;
cnt++;
for(auto x:g[u]){
if(x==p)continue;
dfs(x,u);
}
}
int getmn(int L,int R)
{
int j=lo[R-L+1];
int ret=min(mn[L][j],mn[R-(1<<j)+1][j]);
return ret;
}
int getmx(int L,int R)
{
int j=lo[R-L+1];
int ret=max(mx[L][j],mx[R-(1<<j)+1][j]);
return ret;
}
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;
lo[1]=0;
for(int i=2;i<=n+100;i++){
lo[i]=lo[i/2]+1;
}
for(int i=0;i<n-1;i++){
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
for(int i=0;i<N;i++){
if(g[i].size()==1){
dfs(i,i);
break;
}
}
for(int i=0;i<n;i++){
mn[i][0]=a[i];
mx[i][0]=a[i];
}
for(int j=1;j<Le;j++){
for(int i=0;i+(1<<j)<=n;i++){
mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
}
}
vector<int> ret;
for(int t=0;t<S.size();t++){
int a=idx[S[t]];
int b=idx[E[t]];
if(a<L[t]||b>R[t]){
ret.push_back(0);
continue;
}
int l=a,r=n-1,r1;
while(l<=r){
int mid=(l+r)/2;
if(getmn(a,mid)>=L[t]){
l=mid+1;
r1=mid;
}
else{
r=mid-1;
}
}
l=0,r=a;
int l1;
while(l<=r){
int mid=(l+r)/2;
if(getmn(a,mid)>=L[t]){
r=mid-1;
l1=mid;
}
else{
l=mid+1;
}
}
l=a,n-1;
int r2;
while(l<=r){
int mid=(l+r)/2;
if(getmx(b,mid)<=R[t]){
l=mid+1;
r2=mid;
}
else{
r=mid-1;
}
}
l=0,r=b;
int l2;
while(l<=r){
int mid=(l+r)/2;
if(getmx(b,mid)<=R[t]){
r=mid-1;
l2=mid;
}
else{
l=mid+1;
}
}
ret.push_back(max(l1,l2)<=min(r1,r2));
}
return ret;
}
Compilation message
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:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int t=0;t<S.size();t++){
| ~^~~~~~~~~
werewolf.cpp:101:14: warning: right operand of comma operator has no effect [-Wunused-value]
101 | l=a,n-1;
| ~^~
werewolf.cpp:114:13: warning: 'l2' may be used uninitialized in this function [-Wmaybe-uninitialized]
114 | int l2;
| ^~
werewolf.cpp:88:13: warning: 'l1' may be used uninitialized in this function [-Wmaybe-uninitialized]
88 | int l1;
| ^~
werewolf.cpp:102:13: warning: 'r2' may be used uninitialized in this function [-Wmaybe-uninitialized]
102 | int r2;
| ^~
werewolf.cpp:76:23: warning: 'r1' may be used uninitialized in this function [-Wmaybe-uninitialized]
76 | int l=a,r=n-1,r1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
43304 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
43304 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
354 ms |
125748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
43304 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |