#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;
int M,Q,N;
vvi paths(2e5+6,vi());
vi arr,node_to_pos;
vvi seg_tree(2, vi(8e5+6,-1));
bool ans_found = 0;
void dfs(int pos,int a,int b){
if(pos == N)return;
arr[pos] = a;
for(int i:paths[a]){
if(i==b)continue;
dfs(pos+1,i,a);
}
}
void construct(int ss,int se,int pos,int type){
if(ss == se){
seg_tree[type][pos] = arr[ss];
return;
}
int mid = (ss+se)/2;
construct(ss,mid,pos*2,type);
construct(mid+1,se,pos*2+1,type);
if(type == 0){
seg_tree[type][pos] = min(seg_tree[type][pos*2],seg_tree[type][pos*2+1]);
}else{
seg_tree[type][pos] = max(seg_tree[type][pos*2],seg_tree[type][pos*2+1]);
}
}
int get_val(int ss,int se,int pos,int type,int qs,int qe){
// cout << ss << " " << se << " " << pos << " " << qs << " " << qe << " " << type << endl;
if(qs == ss && qe == se)return seg_tree[type][pos];
if (se < qs || ss > qe){
if(type == 0)return 2e9;
return 0;
}
int mid = (ss+se)/2;
if(type == 0){
return min(get_val(ss,mid,pos*2,type,qs,min(qe,mid)),get_val(mid+1,se,pos*2+1,type,max(qs,mid+1),qe));
}else{
return max(get_val(ss,mid,pos*2,type,qs,min(qe,mid)),get_val(mid+1,se,pos*2+1,type,max(qs,mid+1),qe));
}
}
void binary(int S,int E,int L,int R){
int l = S,r = E;
while(r>l){
int mid = (l+r)/2;
int val = get_val(0,N-1,1,0,S,mid);
// cout << l << " " << mid << " " << r << " " << val << endl;
if(val >= R){
l=mid+1;
}else{
r=mid;
}
}
// cout << l << endl;
// return;
int human_min = l;
l = S,r = E;
while(r>l){
int mid = (l+r)/2;
int val = get_val(0,N-1,1,1,mid,E);
// cout << l << " " << mid << " " << r << " " << val << endl;
if(val <= L){
r=mid-1;
}else{
l=mid;
}
}
// cout << l << endl;
int wolf_max = l;
ans_found = (human_min>=wolf_max);
}
vi check_validity(int n, vi X, vi Y, vi S, vi E ,vi L, vi R) {
N = n;M = X.size(); Q = L.size();
arr = vi(n), node_to_pos = vi(n,0);
vi ans(Q);
FOR(i,0,M){
paths[X[i]].pb(Y[i]);
paths[Y[i]].pb(X[i]);
}
int head = -1;
FOR(i,0,N){
if(paths[i].size() == 1){head = i;break;}
}
dfs(0,head,-1);
FOR(i,0,N){
node_to_pos[arr[i]] = i;
}
// for(int i:arr)cout << i << " ";
// cout << endl;
// for(int i:node_to_pos)cout << i << " ";
// cout << endl;
construct(0,n-1,1,0);
construct(0,n-1,1,1);
// cout << "##########" << endl;
// FOR(i,0,13)cout << seg_tree[0][i] << " ";
// cout << endl;
// FOR(i,0,13)cout << seg_tree[1][i] << " ";
// cout << endl;
// cout << get_val(0,N-1,1,0,1,5) << " ";
// return ans;
// FOR(i,0,N){
// FOR(j,i+1,N){
// cout << get_val(0,N,1,0,i,j) << " ";
// }cout << endl;
// }cout << endl;
// FOR(i,0,N){
// FOR(j,i+1,N){
// cout << get_val(0,N,1,1,i,j) << " ";
// }cout << endl;
// }cout << endl;
FOR(i,0,Q){
ans_found = 0;
vi visited(N,0);
S[i] = node_to_pos[S[i]];
E[i] = node_to_pos[E[i]];
if(S[i] > E[i])swap(S[i],E[i]);
binary(S[i],E[i],L[i],R[i]);
ans[i] = ans_found;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4078 ms |
14428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4078 ms |
14428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4053 ms |
47900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4078 ms |
14428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |