Submission #1013653

# Submission time Handle Problem Language Result Execution time Memory
1013653 2024-07-03T18:27:58 Z MarwenElarbi Werewolf (IOI18_werewolf) C++17
0 / 100
2505 ms 230432 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=2e5+5;
vector<int> adj[nax];
int n;
int segtree[nax*4][2];
int tab[nax];
void build(int pos,int l,int r){
    if(l==r){
        segtree[pos][0]=segtree[pos][1]=tab[l];
        return;
    }
    int mid=(r+l)/2;
    build(pos*2+1,l,mid);
    build(pos*2+2,mid+1,r);
    segtree[pos][0]=min(segtree[pos*2+1][0],segtree[pos*2+2][0]);
    segtree[pos][1]=max(segtree[pos*2+1][1],segtree[pos*2+2][1]);
    return;
}
int query0(int pos,int l,int r,int left,int right){
    if(l>r||l>right||r<left) return 1e9;
    if(l>=left&&r<=right) return segtree[pos][0];
    int mid=(r+l)/2;
    return min(query0(pos*2+1,l,mid,left,right),query0(pos*2+2,mid+1,r,left,right));
}
int query1(int pos,int l,int r,int left,int right){
    if(l>r||l>right||r<left) return -1e9;
    if(l>=left&&r<=right) return segtree[pos][1];
    int mid=(r+l)/2;
    return max(query1(pos*2+1,l,mid,left,right),query1(pos*2+2,mid+1,r,left,right));
}
int bs_min_left(int x,int cur){
    int l=-1;
    int r=x;
    while(r-l>1){
        int mid=(r+l)/2;
        if (query0(0,0,n-1,mid,x)>=cur)
            r=mid;
        else l=mid;
    }
    return r;
}
int bs_min_right(int x,int cur){
    int l=x;
    int r=n;
    while(r-l>1){
        int mid=(r+l)/2;
        if (query0(0,0,n-1,x,mid)>=cur)
            l=mid;
        else r=mid;
    }
    return l;
}
int bs_max_left(int x,int cur){
    int l=-1;
    int r=x;
    while(r-l>1){
        int mid=(r+l)/2;
        if (query1(0,0,n-1,mid,x)<=cur)
            r=mid;
        else l=mid;
    }
    return r;
}
int bs_max_right(int x,int cur){
    int l=x;
    int r=n;
    while(r-l>1){
        int mid=(r+l)/2;
        if (query0(0,0,n-1,x,mid)<=cur)
            l=mid;
        else r=mid;
    }
    return l;
}
set<int> mergesort[nax*4];
void build_mergesort(int pos,int l,int r){
    if(l==r){
        mergesort[pos].insert(tab[l]);
        return;
    }
    int mid=(r+l)/2;
    build_mergesort(pos*2+1,l,mid);
    build_mergesort(pos*2+2,mid+1,r);
    for(auto u:mergesort[pos*2+1]) mergesort[pos].insert(u);
    for(auto u:mergesort[pos*2+2]) mergesort[pos].insert(u);
    return;
}
bool query(int pos,int l,int r,int left,int right,pair<int,int> cur){
    if(l>r||l>right||r<left) return 0;
    if(l>=left&&r<=right){
        return *mergesort[pos].lower_bound(cur.fi)<=cur.se;
    }
    int mid=(r+l)/2;
    return query(pos*2+1,l,mid,left,right,cur)|query(pos*2+2,mid+1,r,left,right,cur);
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R) {
    n=N+1;
    int q=R.size();
    for (int i = 0; i < n-1; ++i)
    {
        tab[i]=X[i];
    }
    tab[n-1]=Y[n-2];
    build(0,0,n-1);
    build_mergesort(0,0,n-1);
    vector<int> ans;
    for (int i = 0; i < q; ++i)
    {
        pair<int,int> cur={L[i],R[i]};
        if(S[i]<cur.fi||E[i]>cur.se){
            ans.pb(0);
            continue;
        }
        bool test=(E[i]>=S[i]);
        pair<int,int> cnt;
        if(test){
            int right=bs_min_right(S[i],cur.fi);
            int left=bs_max_left(E[i],cur.se);
            cnt={left,right};
        }else{
            int right=bs_min_left(S[i],cur.fi);
            int left=bs_max_right(E[i],cur.se);
            cnt={left,right};
        }  
        if(cnt.fi<cnt.se){
            ans.pb(0);
            continue;
        } 
        ans.pb((query(0,0,n-1,cnt.se,cnt.fi,cur)) ? 1 : 0);
    }
    return ans;
}

/*namespace {

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

}  // namespace

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
  int N = read_int();
  int M = read_int();
  int Q = read_int();
  std::vector<int> X(M), Y(M), S(Q), E(Q), L(Q), R(Q);
  for (int j = 0; j < M; ++j) {
    X[j] = read_int();
    Y[j] = read_int();
  }
  for (int i = 0; i < Q; ++i) {
    S[i] = read_int();
    E[i] = read_int();
    L[i] = read_int();
    R[i] = read_int();
  }

  std::vector<int> A = check_validity(N, X, Y, S, E, L, R);
  for (size_t i = 0; i < A.size(); ++i) {
    printf("%d\n", A[i]);
  }
  return 0;
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 43868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 43868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2505 ms 230432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 43868 KB Output isn't correct
2 Halted 0 ms 0 KB -