// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include<random>
#endif
//#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
const int lg = 20, inf = 1e9;
int n, cur;
vector<vector<int>> A;
vector<array<int, 2>> P, Anc, L, R, Dsc, Fin;
vector<vector<array<int, 2>>> Up;
int find(int ind, int id) {
if (P[ind][id] == ind) {
return ind;
}
return P[ind][id] = find(P[ind][id], id);
}
array<int, 2> cnt;
void merge(int a, int b, int id) {
int ga = find(a, id), gb = find(b, id);
if (ga == gb) {
return ;
}
assert(cnt[id] >= n);
Anc[cnt[id]][id] = cur;
L[cnt[id]][id] = ga, R[cnt[id]][id] = gb;
Up[ga][0][id] = Up[gb][0][id] = P[ga][id] = P[gb][id] = cnt[id]++;
return;
}
array<int, 2> time_;
void build(int u, int id) {
Dsc[u][id] = time_[id]++;
if (Up[u][0][id] == -1) {
Up[u][0][id] = u;
}
for (int j = 1; j <= lg; j++) {
Up[u][j][id] = Up[Up[u][j - 1][id]][j - 1][id];
}
if (u >= n) {
build(L[u][id], id);
build(R[u][id], id);
}
Fin[u][id] = time_[id]++;
}
int lca(int u, int c, int id) {
for (int j = lg; j >= 0; j--) {
if (Anc[Up[u][j][id]][id] <= c) {
u = Up[u][j][id];
}
}
return u;
}
vector<int> check_validity(int nn, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> LL, vector<int> RR) {
n = nn;
cnt[0] = cnt[1] = n;
A.resize(n), P.resize(2 * n), Anc.resize(2 * n, {inf, inf}), L.resize(2 * n, {-1, -1}), R.resize(2 * n, {-1, -1}), Dsc.resize(2 * n), Fin.resize(2 * n);
Up.resize(2 * n, vector<array<int, 2>>(lg + 1, {-1, -1}));
for (int i = 0; i < 2 * n; i++) {
P[i][0] = P[i][1] = i;
}
for (int i = 0; i < X.size(); i++) {
A[X[i]].push_back(Y[i]);
A[Y[i]].push_back(X[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < A[i].size(); j++) {
if (A[i][j] < i) {
cur = i;
merge(i, A[i][j], 0);
}
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < A[i].size(); j++) {
if (A[i][j] > i) {
cur = n - 1 - i;
merge(i, A[i][j], 1);
}
}
}
build(cnt[0] - 1, 0);
build(cnt[1] - 1, 1);
vector<int> Ans(LL.size());
for (int i = 0; i < S.size(); i++) {
int u = lca(S[i], RR[i], 0), v = lca(E[i], (n - 1) - LL[i], 1);
for (int j = 0; j < n; j++) {
if (Dsc[u][0] <= Dsc[j][0] && Dsc[j][0] <= Fin[u][0]) {
if (Dsc[v][1] <= Dsc[j][1] && Dsc[j][1] <= Fin[v][1]) {
Ans[i] = 1;
}
}
}
}
return Ans;
}
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:194:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
194 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
werewolf.cpp:200:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
200 | for (int j = 0; j < A[i].size(); j++) {
| ~~^~~~~~~~~~~~~
werewolf.cpp:208:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
208 | for (int j = 0; j < A[i].size(); j++) {
| ~~^~~~~~~~~~~~~
werewolf.cpp:221:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
221 | for (int i = 0; i < S.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4064 ms |
127120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |