답안 #819278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819278 2023-08-10T08:49:24 Z vjudge1 늑대인간 (IOI18_werewolf) C++17
15 / 100
1151 ms 67136 KB
#include<bits/stdc++.h>
#include "werewolf.h"

using namespace std;

template<typename T>
struct SparseTable {
    int len;
    vector<vector<T>> st;
    T (*F) (T, T);
    void init(vector<T> &a, T (*f) (T, T)) {
        F = f;
        len = (int)a.size();
        int mxpw = 32 - __builtin_clz(len);
        st.resize(mxpw);
        st[0] = a;
        for(int k = 1; k < mxpw; k++) {
            st[k].resize(len - (1 << k));
            for(int i = 0; i < (int)st[k].size(); i++) 
                st[k][i] = F(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
        }
    }
    T get(int l, int r) {
        if(l > r || l < 0 || r >= len) {
            cerr << "Wrong range in Sparse Table\n";
            cerr << "size = " << len << '\n';
            cerr << "range query: " << '[' << l << ", " << r <<  ']' << '\n';
            exit(1);
        }
        int mxpw = 31 - __builtin_clz(r - l + 1);
        return F(st[mxpw][l], st[mxpw][r - (1 << mxpw) + 1]);
    }
};

int n, m, q;
const int N = 2e5 + 10;
vector<int> g[N];

vector<int> cnt;
vector<bool> us;
void dfs(int s, int l, int r) {
    us[s] = 1;
    cnt[s]++;
    for(int to : g[s]) {
        if(us[to] || to > r || to < l) continue;
        dfs(to, l, r);
    }
}

vector<int> order;
int tin[N];

void tour(int s, int p) {
    tin[s] = (int)order.size();
    order.push_back(s);
    for(int to : g[s]) 
        if(to != p) 
            tour(to, s);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                                  vector<int> S, vector<int> E,
                                  vector<int> L, vector<int> R) {
    n = N, m = (int)X.size(), q = (int)S.size();
    vector<int> res(q);
    
    for(int i = 0; i < m; i++) {
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }

    if(n <= 3000 && q <= 3000) {
        for(int i = 0; i < q; i++) {
            cnt.assign(n, 0);
            us.assign(n, false);
            dfs(S[i], L[i], n - 1);
            us.assign(n, false);
            dfs(E[i], 0, R[i]);
            if(*max_element(cnt.begin(), cnt.end()) > 1)
                res[i] = 1;
        }
        return res;
    }
    int root = 0;
    while(root < n && g[root].size() > 1) root++;
    tour(root, root);
    SparseTable<int> mn, mx;
    mn.init(order, [](int a, int b) {return (a > b ? b : a);});
    mx.init(order, [](int a, int b) {return (a < b ? b : a);});
    for(int i = 0; i < q; i++) {
        int x = tin[S[i]], y = tin[E[i]], lb, rb;
        int sl = x, sr = x, el = y, er = y;
        lb = x, rb = n;
        while(rb - lb > 1) {
            int mid = (lb + rb) / 2;
            if(mn.get(x, mid) >= L[i]) lb = mid;
            else rb = mid;
        }
        sr = lb;
        
        lb = -1, rb = x;
        while(rb - lb > 1) {
            int mid = (lb + rb) / 2;
            if(mn.get(mid, x) >= L[i]) rb = mid;
            else lb = mid;
        }
        sl = rb;
        
        lb = y, rb = n;
        while(rb - lb > 1) {
            int mid = (lb + rb) / 2;
            if(mx.get(y, mid) <= R[i]) lb = mid;
            else rb = mid;
        }
        er = lb;
        
        lb = -1, rb = y;
        while(rb - lb > 1) {
            int mid = (lb + rb) / 2;
            if(mx.get(mid, y) <= R[i]) rb = mid;
            else lb = mid;
        }
        el = rb;
        int ll = max(sl, el), rr = min(sr, er);
        
        res[i] = (ll <= rr);
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5000 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4920 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5000 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4920 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 199 ms 5384 KB Output is correct
11 Correct 102 ms 5340 KB Output is correct
12 Correct 21 ms 5404 KB Output is correct
13 Correct 231 ms 5384 KB Output is correct
14 Correct 142 ms 5348 KB Output is correct
15 Correct 181 ms 5532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1151 ms 59412 KB Output is correct
2 Correct 435 ms 67020 KB Output is correct
3 Incorrect 483 ms 67136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5000 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4920 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 199 ms 5384 KB Output is correct
11 Correct 102 ms 5340 KB Output is correct
12 Correct 21 ms 5404 KB Output is correct
13 Correct 231 ms 5384 KB Output is correct
14 Correct 142 ms 5348 KB Output is correct
15 Correct 181 ms 5532 KB Output is correct
16 Correct 1151 ms 59412 KB Output is correct
17 Correct 435 ms 67020 KB Output is correct
18 Incorrect 483 ms 67136 KB Output isn't correct
19 Halted 0 ms 0 KB -