Submission #610972

# Submission time Handle Problem Language Result Execution time Memory
610972 2022-07-28T20:48:22 Z fvogel499 Werewolf (IOI18_werewolf) C++17
0 / 100
366 ms 52300 KB
#include "werewolf.h"
#include <bits/stdc++.h>

#define sz(x) ((x).size())

using namespace std;

const int inf = 1e9;
const int p2 = 1<<18;

struct Segtree {
    Segtree() {
        t = new int [p2*2];
        for (int i = 0; i < p2*2; i++) t[i] = -inf;
    }
    void upd(int x, int v) {
        for (x += p2; x; x /= 2) {
            t[x] = max(t[x], v);
        }
    }
    int get(int b, int e) {
        int r = -inf;
        b += p2;
        e += p2;
        while (b <= e) {
            if (b%2 == 1) {
                r = max(r, t[b]);
                b++;
            }
            if (e%2 == 0) {
                r = max(r, t[e]);
                e--;
            }
            b /= 2;
            e /= 2;
        }
        return r;
    }
    int* t;
};

std::vector<int> check_validity(const int n, std::vector<int> edgeX, std::vector<int> edgeY, std::vector<int> queryX, std::vector<int> queryY, std::vector<int> queryLB, std::vector<int> queryRB) {
    vector<int> graph [n];
    for (int i = 0; i < sz(edgeX); i++) {
        graph[edgeX[i]].push_back(edgeY[i]);
        graph[edgeY[i]].push_back(edgeX[i]);
    }
    vector<int> path;
    for (int i = 0; i < n; i++) if (sz(graph[i]) == 1) {
        bool vis [n];
        for (int j = 0; j < n; j++) vis[j] = false;
        int x = i;
        while (1) {
            vis[x] = true;
            path.push_back(x);
            bool ch = false;
            for (int y : graph[x]) if (!vis[y]) {
                x = y;
                ch = true;
                break;
            }
            if (!ch) {
                break;
            }
        }
        break;
    }
    assert(sz(path) == n);
    int invPath [n];
    for (int i = 0; i < n; i++) invPath[path[i]] = i;
    const int nbQ = sz(queryX);
    vector<int> queriesSmallerThan [n];
    int latestPerQuery [nbQ];
    vector<int> queriesBiggerThan [n];
    int earliestPerQuery [nbQ];
    for (int i = 0; i < nbQ; i++) {
        if (queryLB[i] >= 1) {
            queriesSmallerThan[queryLB[i] - 1].push_back(i);
        }
        else {
            latestPerQuery[i] = -1;
        }
        if (queryRB[i]+1 < n) {
            queriesBiggerThan[queryRB[i] + 1].push_back(i);
        }
        else {
            earliestPerQuery[i] = n;
        }
    }
    Segtree st = Segtree();
    for (int i = 0; i < n; i++) {
        st.upd(invPath[i], invPath[i]);
        for (int j : queriesSmallerThan[i]) {
            latestPerQuery[j] = st.get(queryX[j], queryY[j]);
        }
    }
    st = Segtree();
    for (int i = n-1; i >= 0; i--) {
        st.upd(invPath[i], -invPath[i]);
        for (int j : queriesBiggerThan[i]) {
            earliestPerQuery[j] = -st.get(queryX[j], queryY[j]);
        }
    }
    vector<int> res(nbQ);
    for (int i = 0; i < nbQ; i++) {
        res[i] = (latestPerQuery[i]+1 < earliestPerQuery[i]);
    }
    return res;
}

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:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < sz(edgeX); i++) {
      |                       ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from werewolf.cpp:2:
werewolf.cpp:68:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   68 |     assert(sz(path) == n);
      |                     ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 366 ms 52300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -