#include "werewolf.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
const int NMAX = 2e5+1;
int seg1[NMAX*4],seg2[NMAX*4];
vi arr;
vvi paths(NMAX);
int N;
void dfs(int pos,int prev){
arr.pb(pos);
for(int i:paths[pos]){
if(i==prev)continue;
dfs(i,pos);
}
}
void build(int pos,int l,int r){
if(l==r){
seg1[pos] = arr[l];
seg2[pos] = arr[l];
return;
}
int mid = (l+r)/2;
build(2*pos+1,l,mid);
build(2*pos+2,mid+1,r);
seg1[pos] = min(seg1[2*pos+1],seg1[2*pos+2]);
seg2[pos] = max(seg2[2*pos+1],seg2[2*pos+2]);
}
int get_min(int pos,int l,int r,int ql,int qr){
if(qr<l || ql>r){
return NMAX;
}
if(l>=ql && r<=qr){return seg1[pos];}
int mid = (l+r)/2;
return min(get_min(2*pos+1,l,mid,ql,qr),get_min(2*pos+2,mid+1,r,ql,qr));
}
int get_max(int pos,int l,int r,int ql,int qr){
if(qr<l || ql>r){
return 0;
}
if(l>=ql && r<=qr){return seg2[pos];}
int mid = (l+r)/2;
return max(get_max(2*pos+1,l,mid,ql,qr),get_max(2*pos+2,mid+1,r,ql,qr));
}
int check(int S,int E,int L,int R){
int l = S,r =E;
while(l>r){
int mid = (l+r)/2;
if(get_min(0,0,N-1,l,mid) >= L){
l = mid;
}else{
r = mid;
}
}
int a = l;
l = S;r =E;
while(l>r){
int mid = (l+r)/2;
if(get_max(0,0,N-1,l,mid) <= R){
r = mid;
}else{
l = mid;
}
}
int b = l;
return a == b;
}
vi check_validity(int n, vi X, vi Y, vi S, vi E ,vi L, vi R) {
N = n;
vi ans;
int M = X.size();
FOR(i,0,M){
paths[X[i]].pb(Y[i]);
paths[Y[i]].pb(X[i]);
}
int head;
FOR(i,0,M){if(paths[i].size() == 1){head = i;break;}}
dfs(head,-1);
// cout << endl;
// for(int i:arr)cout << i << " ";
// cout << endl;
build(0,0,n-1);
// get_min(0,0,n-1,i,j);
FOR(i,0,S.size()){
ans.pb(check(S[i],E[i],L[i],R[i]));
}
return ans;
}
Compilation message
werewolf.cpp: In function 'vi check_validity(int, vi, vi, vi, vi, vi, vi)':
werewolf.cpp:21:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | #define FOR(i, a, b) for (int i = a; i < (b); i++)
| ^
werewolf.cpp:132:3: note: in expansion of macro 'FOR'
132 | FOR(i,0,S.size()){
| ^~~
werewolf.cpp:122:6: warning: 'head' may be used uninitialized in this function [-Wmaybe-uninitialized]
122 | dfs(head,-1);
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
331 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
331 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4082 ms |
44644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
331 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |