Submission #1072543

# Submission time Handle Problem Language Result Execution time Memory
1072543 2024-08-23T21:34:56 Z ewirlan Werewolf (IOI18_werewolf) C++17
0 / 100
3218 ms 84432 KB
//
#ifndef __SIZEOF_INT128__
  #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
constexpr int maxn = 2e5 + 3;
vector <int> graf[maxn];
int rep[maxn][2];
int find(int w, bool b){
    if(!~rep[w][b])return w;
    return rep[w][b] = find(rep[w][b], b);
}
vector <int> syn[maxn][2];
int ojc[maxn][20][2];
vector <int> pv[2];
int pro[maxn][2], poo[maxn][2];
void dfs(int w, bool b){
    pro[w][b] = sz(pv[b]);
    pv[b].pb(w);
    for(auto i: syn[w][b])dfs(i, b);
    poo[w][b] = sz(pv[b])-1;
}
vector <int> check_validity (int n, vector <int> x, vector <int> y, vector <int> a, vector <int> b, vector <int> l, vector <int> r)
{
    int m(sz(x)), q(sz(a));
    pv[0].clear();
    pv[1].clear();
    rep(i, 0, n){
        syn[i][0].clear();
        syn[i][1].clear();
        graf[i].clear();
        rep[i][0] = rep[i][1] = -1;
    }
    rep(i, 0, m){
        graf[x[i]].pb(y[i]);
        graf[y[i]].pb(x[i]);
    }
    rep(i, 0, n)ojc[i][0][0] = ojc[i][0][1] = i;
    rep(i, 0, n){
        set <int> s;
        for(auto j: graf[i])if(j < i)s.insert(find(j, 0));
        for(auto j: s){
            syn[i][0].pb(j);
            rep[j][0] = i;
            ojc[j][0][0] = i;
        }
    }
    per(i, n-1, -1){
        set <int> s;
        for(auto j: graf[i])if(j > i)s.insert(find(j, 1));
        for(auto j: s){
            syn[i][1].pb(j);
            rep[j][1] = i;
            ojc[j][0][1] = i;
        }
    }
    rep(b, 0, 2)rep(k, 1, 20)rep(i, 0, n)ojc[i][k][b] = ojc[ojc[i][k-1][b]][k-1][b];
    dfs(0, 1);
    dfs(n-1, 0);
    cout <<pv[0] << '\n' << pv[1] << '\n';
    vector <int> odp;
    rep(i, 0, q){
        int k(19);
        while(a[i] != ojc[a[i]][0][1] && ojc[a[i]][0][1] >= l[i]){
            while(k && ojc[a[i]][k][1] < l[i])--k;
            a[i] = ojc[a[i]][k][1];
        }
        k = 19;
        while(b[i] != ojc[b[i]][0][0] && ojc[b[i]][0][0] <= r[i]){
            while(k && ojc[b[i]][k][0] > r[i])--k;
            b[i] = ojc[b[i]][k][0];
        }
        
        int p1(pro[a[i]][1]), k1(poo[a[i]][1]), p0(pro[b[i]][0]), k0(poo[b[i]][0]);
        bool c(0);
        rep(i, p1, k1+1)rep(j, p0, k0+1)c |= pv[1][i] == pv[0][j];
        odp.pb(c);
    }
    return odp;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 21596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 21596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3218 ms 84432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 21596 KB Output isn't correct
2 Halted 0 ms 0 KB -