Submission #1045550

# Submission time Handle Problem Language Result Execution time Memory
1045550 2024-08-06T05:35:25 Z SiliconSquared Werewolf (IOI18_werewolf) C++14
15 / 100
186 ms 40136 KB
#include "werewolf.h"
using namespace std;
#include <vector>
#include <cmath>
#define INF 999999999
struct node{
    int x;
    vector<int> v;
    bool g,h;
    node(){}
};
vector<node> v;
std::vector<int> sub1(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) {
    v.resize(n);
    for (int i=0;i<X.size();i++){
        v[X[i]].v.push_back(Y[i]);
        v[Y[i]].v.push_back(X[i]);
    }
    vector<int> q;
    vector<int> z;
    z.resize(S.size());
    int p;
    bool f;
    for (int _=0;_<S.size();_++){
        for (int i=0;i<n;i++){v[i].g=false;v[i].h=false;}
        q.clear();
        q.push_back(S[_]);
        f=false;
        while (!q.empty()){
            p=q[q.size()-1];
            q.pop_back();
            if (v[p].g||p<L[_]){continue;}
            v[p].g=true;
            for (int i:v[p].v){
                q.push_back(i);
            }
        }
        q.clear();
        q.push_back(E[_]);
        while (!q.empty()){
            p=q[q.size()-1];
            q.pop_back();
            if (v[p].h||p>R[_]){continue;}
            if (v[p].g){f=true;break;}
            v[p].h=true;
            for (int i:v[p].v){
                q.push_back(i);
            }
        }
        z[_]=f;
    }
    return z;
}
struct seg{
    int s,x,y,z;
    seg(){}
    seg(int _x,int _z){
        s=INF;x=_x;z=_z;y=(x+z)/2;
    }
};
struct segtree{
    int n;
    vector<seg> v;
    segtree(){}
    segtree(int _n){
        n=pow(2,ceil(log2(_n)));
        v.resize(n*2);
        v[1]=seg(0,n);
        for (int i=2;i<n*2;i++){
            if (i%2==0){v[i]=seg(v[i/2].x,v[i/2].y);}
            else{v[i]=seg(v[i/2].y,v[i/2].z);}
        }
    }
    void update(int i,int s){
        i+=n;
        v[i].s=s;
        while (i!=1){
            i/=2;
            v[i].s=min(v[i*2].s,v[i*2+1].s);
        }
    }
    int query(int a,int b,int i){
        if (a>=b){return INF;}
        if (a==v[i].x&&b==v[i].z){return v[i].s;}
        return min(query(a,min(b,v[i].y),i*2),query(max(a,v[i].y),b,i*2+1));
    }
    int walk(int a,int s){
        int i=a+n;
        if (v[i].s<s){return a;}
        if (v[1].s>=s){return INF;}
        i/=2;
        while (v[i*2+1].s>=s){
            i/=2;
        }
        while (v[i].x+1!=v[i].z){
            if (v[i*2].s<s){
                i*=2;
            }else{
                i=i*2+1;
            }
        }
        return i-n;
    }
};
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) {
    if (n<=3000 && X.size()<=6000 and S.size()<=3000){return sub1(n,X,Y,S,E,L,R);}
    vector<int> w;
    vector<int> m;
    vector<vector<int>> raw;
    raw.resize(n);
    for (int i=0;i<n-1;i++){
        raw[X[i]].push_back(Y[i]);
        raw[Y[i]].push_back(X[i]);
    }
    int x,y;
    for (int i=0;i<n;i++){
        if (raw[i].size()==1){x=i;break;}
    }
    y=-1;
    for (int i=0;i<n-1;i++){
        w.push_back(x);
        if (raw[x][0]==y){y=x;x=raw[x][1];}
        else{y=x;x=raw[x][0];}
    }
    w.push_back(x);
    segtree pos=segtree(n);//search for max, walk to next thing smaller than s
    segtree neg=segtree(n);
    m.resize(n);
    for (int i=0;i<n;i++){
        pos.update(i,w[i]);
        neg.update(i,-w[i]);
        m[w[i]]=i;
    }
    int a,b,l,r;
    bool f;
    vector<int> z;
    for (int i=0;i<S.size();i++){//print(i);
        a=S[i];b=E[i];l=L[i];r=R[i];
        f=true;
        if (m[a]<m[b]){
            a=pos.walk(a,l);
            b=m[b];
            if (a>b){a=b+1;}
            if (w[a-1]>r){f=false;}
            if (neg.query(a,b,1)<-r){f=false;}
        }else{
            a=m[a];
            b=neg.walk(b,-r);
            if (b>a){b=a+1;}//print(a);print(b);
            if (w[b-1]<l){f=false;}
            if (pos.query(b,a,1)<l){f=false;}
        }
        z.push_back(f);
    }
    return z;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> sub1(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i=0;i<X.size();i++){
      |                  ~^~~~~~~~~
werewolf.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int _=0;_<S.size();_++){
      |                  ~^~~~~~~~~
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:139:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |     for (int i=0;i<S.size();i++){//print(i);
      |                  ~^~~~~~~~~
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 77 ms 872 KB Output is correct
11 Correct 43 ms 604 KB Output is correct
12 Correct 11 ms 860 KB Output is correct
13 Correct 76 ms 876 KB Output is correct
14 Correct 47 ms 860 KB Output is correct
15 Correct 118 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 186 ms 40136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 77 ms 872 KB Output is correct
11 Correct 43 ms 604 KB Output is correct
12 Correct 11 ms 860 KB Output is correct
13 Correct 76 ms 876 KB Output is correct
14 Correct 47 ms 860 KB Output is correct
15 Correct 118 ms 968 KB Output is correct
16 Incorrect 186 ms 40136 KB Output isn't correct
17 Halted 0 ms 0 KB -