#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or substracting them
//only step by step debug when necessay
//the only time I thought this could be solved wihtout segment trees segment tree was the answer fml
constexpr int N = 1e2; //change
struct segtree
{
int mx[N] = {0}, mn[N], size = 1;
segtree(int n){while(size<=n)size*=2; fill(mn,mn+N,INT_MAX);}
void upd(int i, int u){
upd(i,u,0,0,size);
}
void upd(int i, int u, int x, int l, int r){
if(r-l==1){
mx[x] = u;
mn[x] = u;
return;
}
int m = (r+l)/2;
if(i<m) upd(i,u,2*x+1,l,m);
else upd(i,u,2*x+2,m,r);
mx[x] = max(mx[2*x+1],mx[2*x+2]);
mn[x] = min(mn[2*x+1],mn[2*x+2]);
}
int get(int l, int r, bool MX){
return get(l,r,0,0,size,MX);
}
int get(int l, int r, int x, int lx, int rx, bool MX){
int* arr = (MX) ? mx : mn;
if(lx>=r||rx<=l) return INT_MAX;
else if(lx>=l&&rx<=r) return arr[x];
int m = (rx+lx)/2;
int p = get(l,r,2*x+1,lx,m,MX);
int q = get(l,r,2*x+2,m,rx,MX);
if(MX) return max(p,q);
else return min(p,q);
}
};
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R){
int n = N,m = X.size(),q = S.size();
vi adj[n];
for (size_t i = 0; i < m; i++)
{
adj[X[i]-1].pb(Y[i]-1);
adj[Y[i]-1].pb(X[i]-1);
}
vi arr;
for (size_t i = 0; i < N; i++)
{
if(adj[i].size()==1){
int e = -1,x = i ;
while(arr.size()<N){
arr.pb(x);
for(int p : adj[x]){
if(p!=e){
e = x;
x = p;
break;
}
}
}
break;
}
}
segtree sg(n);
int ind[n];
for (size_t i = 0; i < n; i++)
{
sg.upd(i,arr[i]);
ind[arr[i]] = i;
}
vi res;
for (size_t i = 0; i < q; i++)
{
int from_start;
if(S[i]>R[i]||E[i]<L[i]){
res.pb(0);
continue;
}
int s = ind[S[i]-1], e = ind[E[i]-1];
//binary search segtree to get the range from start
//and find the furthest index whose min is smaller than R
if(s>e){
int r = s, l = e;
while(r-l>1){
int m = (r+l)/2;
if(sg.get(m,s+1,true)<R[i]) r = m;
else l = m;
}
if(arr[r]<L[i]-1||sg.get(e,l,false)<L[i]-1)
res.pb(0);
else res.pb(1);
}
else{
int l = s, r = e;
while(r-l>1){
int m = (r+l)/2;
if(sg.get(s,m,true)<R[i]) l = m;
else r = m;
}
if(arr[l]<L[i]-1||sg.get(r,e+1,false)<L[i]-1)
res.pb(0);
else res.pb(1);
}
}
return res;
}
// int main()
// {
// fast_cin();
// #ifndef ONLINE_JUDGE
// #ifdef _WIN32
// freopen("input.in", "r", stdin);
// freopen("input.out", "w", stdout);
// #endif
// #endif
// for(int i : check_validity(5,{2,1,4,5},{1,4,5,3},{3},{4},{4},{4})) cout<<i<<' ';
// return 0;
// }
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:65:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | for (size_t i = 0; i < m; i++)
| ~~^~~
werewolf.cpp:71:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
71 | for (size_t i = 0; i < N; i++)
| ~~^~~
werewolf.cpp:75:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
75 | while(arr.size()<N){
| ~~~~~~~~~~^~
werewolf.cpp:90:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
90 | for (size_t i = 0; i < n; i++)
| ~~^~~
werewolf.cpp:96:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
96 | for (size_t i = 0; i < q; i++)
| ~~^~~
werewolf.cpp:98:13: warning: unused variable 'from_start' [-Wunused-variable]
98 | int from_start;
| ^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
116 ms |
38372 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |