Submission #1083668

# Submission time Handle Problem Language Result Execution time Memory
1083668 2024-09-03T18:53:15 Z Tymond Werewolf (IOI18_werewolf) C++17
0 / 100
1050 ms 101640 KB
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct Query{
    int s, e, l, p, id;
    Query(int ns = 0, int ne= 0, int nl= 0, int np= 0, int nid= 0){
        s = ns;
        e = ne;
        l = nl;
        p = np;
        id = nid;
    }
};

bool comp(Query& a, Query& b){
    if(a.p != b.p){
        return a.p < b.p;
    }
    return a.l < b.l;
}

const int MAXN = 2e5 + 7;
vi g[MAXN];
Query tab[MAXN];
vector<pii> repL[MAXN];
int szL[MAXN];
vector<pii> repP[MAXN];
int szP[MAXN];
vi ans;
int n,m, q;

int FindL(int a){
    if(repL[a].back().fi == a){
        return a;
    }
    return FindL(repL[a].back().fi);
}

int FindP(int a){
    if(repP[a].back().fi == a){
        return a;
    }
    return FindP(repP[a].back().fi);
}

vector<pii> vecL[MAXN];
vector<pii> vecP[MAXN];
void genL(int ind){
    vecL[ind] = repL[ind];
    int akt = vecL[ind].back().fi;
    while(akt != repL[akt].back().fi){
        vecL[ind].pb(repL[akt].back());
        akt = repL[akt].back().fi;
    }
}

void genP(int ind){
    vecP[ind] = repP[ind];
    int akt = vecP[ind].back().fi;
    while(akt != repP[akt].back().fi){
        vecP[ind].pb(repP[akt].back());
        akt = repP[akt].back().fi;
    }
}

vi check_validity(int N, vi X, vi Y,vi S, vi E, vi L, vi R) {
    n = N;
    q = sz(S);
    m = sz(X);
    ans.assign(q, 0);
    for(int i = 0; i < m; i++){
        g[X[i]].pb(Y[i]);
        g[Y[i]].pb(X[i]);
    }

    for(int i = 0; i < q; i++){
        tab[i] = Query(S[i], E[i], L[i], R[i], i);
    }

    for(int i = 0; i < n; i++){
        repL[i].pb({i, i});
        szL[i] = 1;
    }

    for(int i = n - 1; i >= 0; i--){
        for(auto u : g[i]){
            if(u > i){
                int rep1 = FindL(i);
                int rep2 = FindL(u);

                if(szL[rep1] > szL[rep2]){
                    szL[rep1] += szL[rep2];
                    repL[rep2].pb({rep1, i});
                }else{
                    szL[rep2] += szL[rep1];
                    repL[rep1].pb({rep2, i});
                }
            }
        }
    }

    for(int i = 0; i < n; i++){
        repP[i].pb({i, i});
        szP[i] = 1;
    }

    for(int i = 0; i < n; i++){
        for(auto u : g[i]){
            if(u < i){
                int rep1 = FindP(i);
                int rep2 = FindP(u);

                if(szP[rep1] > szP[rep2]){
                    szP[rep1] += szP[rep2];
                    repP[rep2].pb({rep1, i});
                }else{
                    szP[rep2] += szP[rep1];
                    repP[rep1].pb({rep2, i});
                }
            }
        }
    }

    for(int i = 0; i < n; i++){
        genL(i);
        genP(i);
    }

    for(int i = 0; i < q; i++){
        //dla s sprawdz vecP, dla e sprawdz vecL
        unordered_map<int, int, custom_hash> cnt;
        int mx = 0;
        //cout << "RIGHT\n";
        for(auto ele : vecL[tab[i].s]){
           // cout << ele.fi << ' ' << ele.se << '\n';
            if(ele.se <= tab[i].p){
               // cout << "---\n";
                for(auto ele2 : vecP[ele.fi]){
                   // cout << ele2.fi << ' ' << ele2.se << '\n';
                    if(ele2.se >= tab[i].l){
                        
                        cnt[ele2.fi] |= 2;
                        mx = max(mx, cnt[ele2.fi]);
                    }
                }
            }
        }
       // cout << "LEFT\n";
        for(auto ele : vecP[tab[i].e]){
            //cout << ele.fi << ' ' << ele.se << '\n';
            if(ele.se >= tab[i].l){
                cnt[ele.fi] |= 1;
                mx = max(mx, cnt[ele.fi]);
            }
        }

        if(mx == 3){
            ans[i] = 1;
        }
    }

    return ans;
}

/*int main(){
    for(auto ele : check_validity(6, {5, 1, 1, 3, 3, 5}, {1, 2, 3, 4, 0, 2},
{4}, {2}, {1}, {2})){
        cout << ele << '\n';
    }
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1050 ms 101640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -