Submission #1048125

# Submission time Handle Problem Language Result Execution time Memory
1048125 2024-08-07T23:47:32 Z SiliconSquared Werewolf (IOI18_werewolf) C++14
49 / 100
222 ms 48880 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[1].s>=s){return INF;}
        bool f;
        if (i%2==0){f=false;}
        else{f=true;}
        i/=2;
        while (v[i*2+1].s>=s || f){
            if (i%2==0){f=false;}
            else{f=true;}
            i/=2;
            if (i==0){return INF;}
        }
        i=i*2+1;
        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);
    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;
        a=m[a];
        b=m[b];//print(a);print(b);
        if (a<b){
            a=pos.walk(a,l);//print(a);print(b);
            if (a>b){a=b+1;}
            if (w[a-1]>r){f=false;}
            if (neg.query(a,b,1)<-r){f=false;}
        }else{
            b=neg.walk(b,-r);//print(a);print(b);
            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:145:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |     for (int i=0;i<S.size();i++){//print(i);
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 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 604 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 86 ms 964 KB Output is correct
11 Correct 39 ms 952 KB Output is correct
12 Correct 10 ms 856 KB Output is correct
13 Correct 75 ms 852 KB Output is correct
14 Correct 46 ms 860 KB Output is correct
15 Correct 120 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 48584 KB Output is correct
2 Correct 170 ms 48584 KB Output is correct
3 Correct 166 ms 48504 KB Output is correct
4 Correct 195 ms 48632 KB Output is correct
5 Correct 208 ms 48616 KB Output is correct
6 Correct 210 ms 48840 KB Output is correct
7 Correct 190 ms 48580 KB Output is correct
8 Correct 166 ms 48616 KB Output is correct
9 Correct 185 ms 48880 KB Output is correct
10 Correct 144 ms 48668 KB Output is correct
11 Correct 170 ms 48628 KB Output is correct
12 Correct 163 ms 48500 KB Output is correct
13 Correct 222 ms 48584 KB Output is correct
14 Correct 192 ms 48824 KB Output is correct
15 Correct 187 ms 48536 KB Output is correct
16 Correct 184 ms 48584 KB Output is correct
17 Correct 191 ms 48580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 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 86 ms 964 KB Output is correct
11 Correct 39 ms 952 KB Output is correct
12 Correct 10 ms 856 KB Output is correct
13 Correct 75 ms 852 KB Output is correct
14 Correct 46 ms 860 KB Output is correct
15 Correct 120 ms 1112 KB Output is correct
16 Correct 213 ms 48584 KB Output is correct
17 Correct 170 ms 48584 KB Output is correct
18 Correct 166 ms 48504 KB Output is correct
19 Correct 195 ms 48632 KB Output is correct
20 Correct 208 ms 48616 KB Output is correct
21 Correct 210 ms 48840 KB Output is correct
22 Correct 190 ms 48580 KB Output is correct
23 Correct 166 ms 48616 KB Output is correct
24 Correct 185 ms 48880 KB Output is correct
25 Correct 144 ms 48668 KB Output is correct
26 Correct 170 ms 48628 KB Output is correct
27 Correct 163 ms 48500 KB Output is correct
28 Correct 222 ms 48584 KB Output is correct
29 Correct 192 ms 48824 KB Output is correct
30 Correct 187 ms 48536 KB Output is correct
31 Correct 184 ms 48584 KB Output is correct
32 Correct 191 ms 48580 KB Output is correct
33 Incorrect 130 ms 48740 KB Output isn't correct
34 Halted 0 ms 0 KB -