답안 #595218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595218 2022-07-13T12:46:51 Z SlavicG 늑대인간 (IOI18_werewolf) C++17
0 / 100
575 ms 131260 KB
#include "werewolf.h"
#include "bits/stdc++.h"
using namespace std;

const int N = 2e5 + 10;
int fen[N];
void modif(int u, int val) {
    for(int i = u + 1; i < N; i += i & -i) fen[i] += val;
}
int query(int l, int r) {
    int ans = 0;
    for(int i = r + 1; i > 0; i -= i & -i) ans += fen[i];
    for(int i = l; i > 0; i -= i & -i) ans -= fen[i];
    return ans;
}

struct dsu {
    vector<int> p;
    dsu(int n) : p(n) {
        iota(p.begin(), p.end(), 0);
    }
    int get(int a) {return p[a] = (a == p[a] ? a : get(p[a]));}
    void uni(int a, int b) {
        a = get(a), b = get(b);
        p[a] = b;
    }
};

void dfs(int u, vector<vector<int>>& adj, vector<int>& in, vector<int>& s, int& t) {
    in[u] = t++;
    s[u] = 1;
    for(int v: adj[u]) {
        dfs(v, adj, in, s, t);
        s[u] += s[v];
    }
}

vector<int> check_validity(int n, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
    int Q = S.size(), A = 0, B = 0;
    vector<vector<int>> adj(n), g1(n), g2(n);
    vector<int> root1(Q), root2(Q), ss[n], ee[n], in1(n), in2(n), s1(n), s2(n);
    for(int i = 0; i < Q; ++i) ss[L[i]].push_back(i), ee[R[i]].push_back(i);
    for(int i = 0; i < (int)X.size(); ++i) adj[X[i]].push_back(Y[i]), adj[Y[i]].push_back(X[i]);
    dsu d1(n), d2(n);
    for(int i = n - 1; i >= 0; --i) {
        for(int j: adj[i]) {
            if(i < j) {
                if(d1.get(j) != i) {
                    g1[i].push_back(d1.get(j));
                    d1.uni(j, i);
                }
            }
        }
        for(int j: ss[i]) root1[j] = d1.get(S[j]);
    }
    for(int i = 0; i < n; ++i) {
        for(int j: adj[i]) {
            if(i > j) {
                if(d2.get(j) != i) {
                    g2[i].push_back(d2.get(j));
                    d2.uni(j, i);
                }
            }
        }
        for(int j: ee[i]) root2[j] = d2.get(E[j]);
    }
    dfs(0, g1, in1, s1, A);
    dfs(n - 1, g2, in2, s2, B);
    vector<int> y[n], queries[n];
    vector<int> cnt(Q, 0);

    //[in1(nodeL), in2(nodeR)], [in1(node) + s1(node) - 1, in2(node) + s2(node) - 1]
    for(int i = 0; i < Q; ++i) {
        int node = root1[i];
        queries[in1[node]].push_back(-i - 1);
        queries[in1[node] + s1[node] - 1].push_back(i);
    }
    for(int i = 0; i < n; ++i) {
        y[in1[i]].push_back(in2[i]);
    }
    for(int i = 0; i < n; ++i) {
        for(int x: queries[i]) {
            if(x >= 0) continue;
            int j = -x + 1;
            int nodeL = root1[i], nodeR = root2[i];
            cnt[j] -= query(in2[nodeR], in2[nodeR] + s2[nodeR] - 1);
        }
        for(int j: y[i]) {
            modif(j, 1);
        }
        for(int x: queries[i]) {
            if(x < 0) continue;
            int j = x;
            int nodeL = root1[i], nodeR = root2[i];
            cnt[j] += query(in2[nodeR], in2[nodeR] + s2[nodeR] - 1);
        }
    }
    for(int i = 0; i < Q; ++i) cout << cnt[i] << "\n";
}

Compilation message

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:85:17: warning: unused variable 'nodeL' [-Wunused-variable]
   85 |             int nodeL = root1[i], nodeR = root2[i];
      |                 ^~~~~
werewolf.cpp:94:17: warning: unused variable 'nodeL' [-Wunused-variable]
   94 |             int nodeL = root1[i], nodeR = root2[i];
      |                 ^~~~~
werewolf.cpp:99:1: warning: no return statement in function returning non-void [-Wreturn-type]
   99 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 575 ms 131260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -