Submission #1083666

# Submission time Handle Problem Language Result Execution time Memory
1083666 2024-09-03T18:36:15 Z Tymond Werewolf (IOI18_werewolf) C++17
Compilation error
0 ms 0 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, int ne, int nl, int np, int nid){
        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], P[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;
        for(auto ele : vecP[tab[i].s]){
            if(ele.se >= tab[i].l && ele.se <= tab[i].p){
                cnt[ele.fi] |= 2;
                mx = max(mx, cnt[ele.fi]);
            }
        }

        for(auto ele : vecL[tab[i].e]){
            if(ele.se >= tab[i].l && ele.se <= tab[i].p){
                cnt[ele.fi] |= 1;
                mx = max(mx, cnt[ele.fi]);
            }
        }

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

    return ans;
}

Compilation message

werewolf.cpp:63:15: error: no matching function for call to 'Query::Query()'
   63 | Query tab[MAXN];
      |               ^
werewolf.cpp:45:5: note: candidate: 'Query::Query(int, int, int, int, int)'
   45 |     Query(int ns, int ne, int nl, int np, int nid){
      |     ^~~~~
werewolf.cpp:45:5: note:   candidate expects 5 arguments, 0 provided
werewolf.cpp:43:8: note: candidate: 'constexpr Query::Query(const Query&)'
   43 | struct Query{
      |        ^~~~~
werewolf.cpp:43:8: note:   candidate expects 1 argument, 0 provided
werewolf.cpp:43:8: note: candidate: 'constexpr Query::Query(Query&&)'
werewolf.cpp:43:8: note:   candidate expects 1 argument, 0 provided
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:116:42: error: 'P' was not declared in this scope
  116 |         tab[i] = Query(S[i], E[i], L[i], P[i], i);
      |                                          ^