Submission #411345

# Submission time Handle Problem Language Result Execution time Memory
411345 2021-05-25T06:20:43 Z usachevd0 Werewolf (IOI18_werewolf) C++14
0 / 100
2461 ms 75456 KB
#include <bits/stdc++.h>
#ifndef LOCAL
    #include "werewolf.h"
#endif

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define Time (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
    return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
    return y > x ? (x = y, true) : false;
}
void debug_out() {
    cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
    cerr << ' ' << A;
    debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
    for (int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}
#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
    #define debug(...) 1337
    #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
    for (auto& x : v)
        stream << x << ' ';
    return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << ' ' << p.second;
}


const int INF32 = 1e9;
const int maxN = 200005;
int n, m, Q;
vector<int> G[maxN];

int timer;
int where[maxN];
vector<pii> hist[maxN];
vector<int> comp[maxN];

void joinR(int x, int y) {
    x = where[x];
    y = where[y];
    if (x == y) return;
    if (comp[x].size() < comp[y].size()) swap(x, y);
    for (int v : comp[y]) {
        where[v] = x;
        while (!hist[v].empty() && hist[v].back().fi == timer)
            hist[v].pop_back();
        hist[v].emplace_back(timer, x);
        comp[x].push_back(v);
    }
    comp[y].clear();
}

void joinL(int x, int y) {
    x = where[x];
    y = where[y];
    if (x == y) return;
    if (comp[x].size() < comp[y].size()) swap(x, y);
    for (int v : comp[y]) {
        where[v] = x;
        comp[x].push_back(v);
    }
    comp[y].clear();
}

int getCompR(int v, int tau) {
    int i = upper_bound(all(hist[v]), mp(tau, INF32)) - hist[v].begin() - 1;
    return hist[v][i].se;
}

vector<int> queL[maxN];

vector<int> check_validity(int _n, vector<int> eu, vector<int> ev, vector<int> qs, vector<int> qt, vector<int> ql, vector<int> qr) {
    n = _n;
    m = eu.size();
    Q = qs.size();
    for (int j = 0; j < m; ++j) {
        int u = eu[j], v = ev[j];
        G[u].push_back(v);
        G[v].push_back(u);
    }
    
    for (int r = 0; r < n; ++r) {
        timer = r;
        where[r] = r;
        comp[r] = {r};
        hist[r].emplace_back(timer, r);
        for (int y : G[r])
            if (y <= r) {
                joinR(y, r);
            }
    }
    
    for (int i = 0; i < Q; ++i) {
        if (qs[i] >= ql[i] && qt[i] <= qr[i])
            queL[ql[i]].push_back(i);
    }
    
    for (int c = 0; c < n; ++c) {
        comp[c].clear();
        where[c] = -1;
    }
    vector<int> ans(Q, 0);
    for (int l = n - 1; l >= 0; --l) {
        where[l] = l;
        comp[l] = {l};
        for (int y : G[l])
            if (y >= l)
                joinL(y, l);
        for (int i : queL[l]) {
            int s = qs[i];
            int t = qt[i];
            int r = qr[i];
            int ct = getCompR(t, r);
            for (int v : comp[where[s]])
                if (getCompR(v, r) == ct) {
                    ans[i] = 1;
                    break;
                }
        }
    }
    return ans;
}


#ifdef LOCAL

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

int32_t main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int N = read_int();
  int M = read_int();
  int Q = read_int();
  std::vector<int> X(M), Y(M), S(Q), E(Q), L(Q), R(Q);
  for (int j = 0; j < M; ++j) {
    X[j] = read_int();
    Y[j] = read_int();
  }
  for (int i = 0; i < Q; ++i) {
    S[i] = read_int();
    E[i] = read_int();
    L[i] = read_int();
    R[i] = read_int();
  }

  std::vector<int> A = check_validity(N, X, Y, S, E, L, R);
  for (size_t i = 0; i < A.size(); ++i) {
    printf("%d\n", A[i]);
  }

    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 15 ms 18988 KB Output is correct
2 Correct 25 ms 19028 KB Output is correct
3 Correct 13 ms 19020 KB Output is correct
4 Correct 13 ms 19080 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 14 ms 19020 KB Output is correct
7 Incorrect 13 ms 19052 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 18988 KB Output is correct
2 Correct 25 ms 19028 KB Output is correct
3 Correct 13 ms 19020 KB Output is correct
4 Correct 13 ms 19080 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 14 ms 19020 KB Output is correct
7 Incorrect 13 ms 19052 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2461 ms 75456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 18988 KB Output is correct
2 Correct 25 ms 19028 KB Output is correct
3 Correct 13 ms 19020 KB Output is correct
4 Correct 13 ms 19080 KB Output is correct
5 Correct 13 ms 19020 KB Output is correct
6 Correct 14 ms 19020 KB Output is correct
7 Incorrect 13 ms 19052 KB Output isn't correct
8 Halted 0 ms 0 KB -