#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <utility>
#include "werewolf.h"
using namespace std;
vector<int> adj[3000]; bool r1[3000], r2[3000];
int cr, cl, n, minvs[600000] = {}, maxvs[600000] = {};
void updh(int i, int s, int e, int l, int u, int d) {
if (s > e || s > u || e < l) {
return;
}
if (s >= l && e <= u) {
minvs[i] = d; maxvs[i] = d; return;
}
updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d);
minvs[i] = min(minvs[i*2+1], minvs[i*2+2]); maxvs[i] = max(maxvs[i*2+1], maxvs[i*2+2]);
}
void updv(int i, int d) {
updh(0, 0, n-1, i, i, d);
}
int minh(int i, int s, int e, int l, int u) {
if (s > e || s > u || e < l) {
return 1000000000;
}
if (s >= l && e <= u) {
return minvs[i];
}
return min(minh(2*i+1, s, (s+e)/2, l, u), minh(2*i+2, (s+e)/2+1, e, l, u));
}
int minv(int l, int u) {
return minh(0, 0, n-1, l, u);
}
int maxh(int i, int s, int e, int l, int u) {
if (s > e || s > u || e < l) {
return -1;
}
if (s >= l && e <= u) {
return maxvs[i];
}
return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u));
}
int maxv(int l, int u) {
return maxh(0, 0, n-1, l, u);
}
void dfs1(int i){
if (i >= cl){
r1[i] = true;
for (int a : adj[i]){
if (a >= cl && !r1[a]){
dfs1(a);
}
}
}
}
void dfs2(int i){
if (i <= cr){
r2[i] = true;
for (int a : adj[i]){
if (a <= cr && !r2[a]){
dfs2(a);
}
}
}
}
void dfs3(int i, int p, int ind){
updv(ind, i);
for (int a : adj[i]){
if (a != p){
dfs3(a, i, ind+1);
}
}
}
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; int Q = S.size(); vector<int> A(Q);
for (int i = 0; i < Q; ++i) {
A[i] = 0;
}
for (int i = 0; i < X.size(); i++){
adj[X[i]].push_back(Y[i]); adj[Y[i]].push_back(X[i]);
}
if (N == X.size() + 1 && N > 3000){
for (int i = 0; i < N; i++){
if (adj[i].size() == 1){
dfs3(i, -1, 0); break;
}
}
for (int i = 0; i < Q; i++) {
cr = R[i]; cl = L[i];
int low = S[i], high = E[i], ub = 0;
if (S[i] >= cl && E[i] <= R[i]){
continue;
}
while (true){
if (low == high){
ub = low;
}
if (low+1 == high){
ub = high;
if (minv(S[i], high) < cl){
ub = low;
}
break;
}
int mid = (low + high)/2;
if (minv(S[i], mid) < cl){
high = mid;
} else {
low = mid;
}
}
low = S[i], high = E[i]; int lb = 0;
while (true){
if (low == high){
lb = low;
}
if (low+1 == high){
lb = low;
if (maxv(low, E[i]) > cr){
lb = high;
}
break;
}
int mid = (low + high)/2;
if (maxv(mid, E[i]) > cr){
low = mid;
} else {
high = mid;
}
}
if (ub >= lb){
A[i] = 1;
}
}
} else {
for (int i = 0; i < Q; i++) {
for (int j = 0; j < N; j++){
r1[j] = false; r2[j] = false;
}
cr = R[i]; cl = L[i];
dfs1(S[i]); dfs2(E[i]);
for (int j = L[i]; j <= R[i]; j++){
if (r1[j] && r2[j]){
A[i] = 1; break;
}
}
}
}
return A;
}
int main(){
int n = 6;
vector<int> x; x.push_back(5); x.push_back(1); x.push_back(1); x.push_back(3); x.push_back(3); x.push_back(5);
vector<int> y; y.push_back(1); y.push_back(2); y.push_back(3); y.push_back(4); y.push_back(0); y.push_back(2);
vector<int> s; s.push_back(4); s.push_back(4); s.push_back(5);
vector<int> e; e.push_back(2); e.push_back(2); e.push_back(4);
vector<int> l; l.push_back(1); l.push_back(2); l.push_back(3);
vector<int> r; r.push_back(2); r.push_back(2); r.push_back(4);
vector<int> a = check_validity(n, x, y, s, e, l, r);
}
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:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < X.size(); i++){
| ~~^~~~~~~~~~
werewolf.cpp:91:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | if (N == X.size() + 1 && N > 3000){
| ~~^~~~~~~~~~~~~~~
/tmp/ccGKSh1C.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc3l9gl1.o:werewolf.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status