Submission #1013601

# Submission time Handle Problem Language Result Execution time Memory
1013601 2024-07-03T17:18:45 Z Malix Werewolf (IOI18_werewolf) C++14
49 / 100
659 ms 524288 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))

ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;

vi mins,maxs,arr,p;
int n;

void build(int k,int l,int r){
  if(l==r){
    mins[k]=arr[l];
    maxs[k]=arr[l];
    return;
  }
  int m=(l+r)/2;
  build(k*2,l,m);
  build(k*2+1,m+1,r);
  mins[k]=min(mins[k*2],mins[k*2+1]);
  maxs[k]=max(maxs[k*2],maxs[k*2+1]);
}

int minq(int k,int x,int y,int l,int r){
  if(x>y)return inf;
  if(x==l&&r==y)return mins[k];
  int m=(l+r)/2;
  return min(minq(k*2,x,min(y,m),l,m),minq(k*2+1,max(m+1,x),y,m+1,r));
}

int maxq(int k,int x,int y,int l,int r){//cerr<<x<<" "<<y<<"\n";
  if(x>y)return 0;
  if(x==l&&r==y)return maxs[k];
  int m=(l+r)/2;
  return max(maxq(k*2,x,min(y,m),l,m),maxq(k*2+1,max(m+1,x),y,m+1,r));
}

int BS(int l,int r,int x,int y,int u,int v){//cerr<<l<<" "<<r<<"\n";
  int m=(l+r)/2;
  int a=minq(1,u,m,0,n-1);
  int b=maxq(1,m+1,v,0,n-1);
  int c=arr[m];//cerr<<a<<" "<<b<<" "<<c<<"\n";
  if(x<=c&&c<=y&&a>=x&&b<=y)return 1;
  if(l==r)return 0;
  if(a<x&&b>y)return 0;
  if(a>=x&&b<=y){
    if(c<x)return BS(l,m,x,y,u,v);
    else return BS(m+1,r,x,y,u,v);
  }
  if(a<x)return BS(l,m,x,y,u,v);
  return BS(m+1,r,x,y,u,v);
}

int BS2(int l,int r,int x,int y,int u,int v){//cerr<<l<<" "<<r<<"\n";
  int m=(l+r)/2;
  int a=maxq(1,u,m,0,n-1);
  int b=minq(1,m+1,v,0,n-1);
  int c=arr[m];
  swap(a,b);//cerr<<a<<" "<<b<<" "<<c<<"\n";
  if(x<=c&&c<=y&&a>=x&&b<=y)return 1;
  if(l==r)return 0;
  if(a<x&&b>y)return 0;
  if(a>=x&&b<=y){
    if(c<x)return BS2(m+1,r,x,y,u,v);
    else return BS2(l,m,x,y,u,v);
  }
  if(a<x)return BS2(m+1,r,x,y,u,v);
  return BS2(l,m,x,y,u,v);
}

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) {
  int Q = S.size();
  if(Q<=3000&&N<=3000&&X.size()<=6000){
    int Q = S.size();
  int m=X.size();
  vii a;
  a.resize(N);
  REP(i,0,m){
    a[X[i]].PB(Y[i]);
    a[Y[i]].PB(X[i]);
  }
  vi ans(Q,0);
  REP(i,0,Q){
    queue<int> pq;
    vi c(N,0),d(N,0);
    pq.push(S[i]);
    while(!pq.empty()){
      int k=pq.front();
      pq.pop();
      if(c[k]||k<L[i])continue;
      c[k]=1;
      for(auto u:a[k])pq.push(u);
    }
    pq.push(E[i]);
    while(!pq.empty()){
      int k=pq.front();
      pq.pop();
      if(d[k]||k>R[i])continue;
      d[k]=1;
      for(auto u:a[k])pq.push(u);
    }
    REP(j,L[i],R[i]+1){
      ans[i]|=(c[j]&d[j]);
    }
  }
  return ans;
  }
  n=N;
  mins.resize(4*N+1);
  maxs.resize(4*N+1);
  int m=X.size();
  vii a;
  a.resize(N);
  REP(i,0,m){
    a[X[i]].PB(Y[i]);
    a[Y[i]].PB(X[i]);
  }
  int k=0;p.resize(N,-1);
  REP(i,0,N)if(a[i].size()==1)k=i;
  arr.PB(k);
  REP(i,0,N-1){
    int c=a[k][0];
    if(arr.size()>=2&&c==arr[arr.size()-2])c=a[k][1];
    arr.PB(c);
    k=c;
  }
  //reverse(arr.begin(),arr.end());
  REP(i,0,N)p[arr[i]]=i;
  build(1,0,n-1);
  vi ans(Q,0);
  REP(i,0,Q){
    if(p[S[i]]<p[E[i]])ans[i]=BS(p[S[i]],p[E[i]],L[i],R[i],p[S[i]],p[E[i]]);
    else ans[i]=BS2(p[E[i]],p[S[i]],L[i],R[i],p[E[i]],p[S[i]]);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 205 ms 876 KB Output is correct
11 Correct 114 ms 1104 KB Output is correct
12 Correct 15 ms 860 KB Output is correct
13 Correct 245 ms 900 KB Output is correct
14 Correct 125 ms 856 KB Output is correct
15 Correct 175 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 29332 KB Output is correct
2 Correct 281 ms 29384 KB Output is correct
3 Correct 289 ms 29312 KB Output is correct
4 Correct 507 ms 29328 KB Output is correct
5 Correct 622 ms 29312 KB Output is correct
6 Correct 659 ms 29564 KB Output is correct
7 Correct 403 ms 29560 KB Output is correct
8 Correct 272 ms 29384 KB Output is correct
9 Correct 259 ms 29380 KB Output is correct
10 Correct 380 ms 29556 KB Output is correct
11 Correct 589 ms 29560 KB Output is correct
12 Correct 468 ms 29380 KB Output is correct
13 Correct 341 ms 29316 KB Output is correct
14 Correct 341 ms 29560 KB Output is correct
15 Correct 342 ms 29308 KB Output is correct
16 Correct 358 ms 29308 KB Output is correct
17 Correct 499 ms 29560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 205 ms 876 KB Output is correct
11 Correct 114 ms 1104 KB Output is correct
12 Correct 15 ms 860 KB Output is correct
13 Correct 245 ms 900 KB Output is correct
14 Correct 125 ms 856 KB Output is correct
15 Correct 175 ms 1116 KB Output is correct
16 Correct 229 ms 29332 KB Output is correct
17 Correct 281 ms 29384 KB Output is correct
18 Correct 289 ms 29312 KB Output is correct
19 Correct 507 ms 29328 KB Output is correct
20 Correct 622 ms 29312 KB Output is correct
21 Correct 659 ms 29564 KB Output is correct
22 Correct 403 ms 29560 KB Output is correct
23 Correct 272 ms 29384 KB Output is correct
24 Correct 259 ms 29380 KB Output is correct
25 Correct 380 ms 29556 KB Output is correct
26 Correct 589 ms 29560 KB Output is correct
27 Correct 468 ms 29380 KB Output is correct
28 Correct 341 ms 29316 KB Output is correct
29 Correct 341 ms 29560 KB Output is correct
30 Correct 342 ms 29308 KB Output is correct
31 Correct 358 ms 29308 KB Output is correct
32 Correct 499 ms 29560 KB Output is correct
33 Runtime error 379 ms 524288 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -