답안 #1072555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072555 2024-08-23T21:55:15 Z ewirlan 늑대인간 (IOI18_werewolf) C++17
15 / 100
4000 ms 87516 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];
        // cerr << a[i] << ' ' << b[i] << ": " << p1 << '-' << k1 <<  ' ' << p0 << '-' << k0 << '\n';
        odp.pb(c);
    }
    return odp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21592 KB Output is correct
2 Correct 5 ms 21596 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 4 ms 21644 KB Output is correct
5 Correct 5 ms 21628 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 4 ms 21608 KB Output is correct
8 Correct 4 ms 21596 KB Output is correct
9 Correct 5 ms 21596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21592 KB Output is correct
2 Correct 5 ms 21596 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 4 ms 21644 KB Output is correct
5 Correct 5 ms 21628 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 4 ms 21608 KB Output is correct
8 Correct 4 ms 21596 KB Output is correct
9 Correct 5 ms 21596 KB Output is correct
10 Correct 3479 ms 22180 KB Output is correct
11 Correct 1741 ms 22160 KB Output is correct
12 Correct 13 ms 22160 KB Output is correct
13 Correct 2862 ms 22276 KB Output is correct
14 Correct 158 ms 22064 KB Output is correct
15 Correct 1876 ms 22288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3200 ms 77540 KB Output is correct
2 Execution timed out 4067 ms 87516 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21592 KB Output is correct
2 Correct 5 ms 21596 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 4 ms 21644 KB Output is correct
5 Correct 5 ms 21628 KB Output is correct
6 Correct 4 ms 21596 KB Output is correct
7 Correct 4 ms 21608 KB Output is correct
8 Correct 4 ms 21596 KB Output is correct
9 Correct 5 ms 21596 KB Output is correct
10 Correct 3479 ms 22180 KB Output is correct
11 Correct 1741 ms 22160 KB Output is correct
12 Correct 13 ms 22160 KB Output is correct
13 Correct 2862 ms 22276 KB Output is correct
14 Correct 158 ms 22064 KB Output is correct
15 Correct 1876 ms 22288 KB Output is correct
16 Correct 3200 ms 77540 KB Output is correct
17 Execution timed out 4067 ms 87516 KB Time limit exceeded
18 Halted 0 ms 0 KB -