Submission #64593747


Source Code Expand

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
template<class T> struct cLtraits_identity{
  using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
  typename conditional<
    is_integral<T>::value,
    make_signed<T>,
    cLtraits_identity<T>
    >::type;
template <class S, class T> struct cLtraits_common_type{
  using tS = typename cLtraits_try_make_signed<S>::type;
  using tT = typename cLtraits_try_make_signed<T>::type;
  using type = typename common_type<tS,tT>::type;
}
;
void*wmem;
char memarr[96000000];
template<class S, class T> inline auto min_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
  return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
struct Rand{
  unsigned x;
  unsigned y;
  unsigned z;
  unsigned w;
  Rand(void){
    x=123456789;
    y=362436069;
    z=521288629;
    w=(unsigned)time(NULL);
  }
  Rand(unsigned seed){
    x=123456789;
    y=362436069;
    z=521288629;
    w=seed;
  }
  inline unsigned get(void){
    unsigned t;
    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;
    w = (w^(w>>19))^(t^(t>>8));
    return w;
  }
  inline double getUni(void){
    return get()/4294967296.0;
  }
  inline int get(int a){
    return (int)(a*getUni());
  }
  inline int get(int a, int b){
    return a+(int)((b-a+1)*getUni());
  }
  inline long long get(long long a){
    return(long long)(a*getUni());
  }
  inline long long get(long long a, long long b){
    return a+(long long)((b-a+1)*getUni());
  }
  inline double get(double a, double b){
    return a+(b-a)*getUni();
  }
  inline int getExp(int a){
    return(int)(exp(getUni()*log(a+1.0))-1.0);
  }
  inline int getExp(int a, int b){
    return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  }
}
;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
template<class T> inline void wt_L(const vector<T> &x);
template<class T> inline void wt_L(const set<T> &x);
template<class T> inline void wt_L(const multiset<T> &x);
template<class T1, class T2> inline void wt_L(const pair<T1,T2> x);
inline void wt_L(const char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class T> struct segtree_Point_SumMin{
  int N;
  int logN;
  T*sum;
  T*mn;
  int*mnind;
  void malloc(int maxN, int once = 0){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    sum = new T[2*i];
    mn = new T[2*i];
    mnind = new int[2*i];
    if(once){
      setN(maxN);
    }
  }
  void walloc(int maxN, int once = 0, void **mem = &wmem){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    walloc1d(&sum, 2*i, mem);
    walloc1d(&mn, 2*i, mem);
    walloc1d(&mnind, 2*i, mem);
    if(once){
      setN(maxN);
    }
  }
  void free(void){
    delete [] sum;
    delete [] mn;
    delete [] mnind;
  }
  T& operator[](int i){
    return sum[N+i];
  }
  void setN(int n, int zerofill = 1, int dobuild = 1){
    int i;
    for(i=1,logN=0;i<n;i*=2,logN++){
      ;
    }
    N = i;
    if(zerofill){
      for(i=(0);i<(N);i++){
        sum[N+i] = 0;
      }
    }
    if(dobuild){
      build();
    }
  }
  void build(void){
    int i;
    for(i=(0);i<(N);i++){
      mn[N+i] = sum[N+i];
      mnind[N+i] = i;
    }
    for(i=N-1;i;i--){
      sum[i] = sum[2*i] + sum[2*i+1];
      if(mn[2*i] <= mn[2*i+1]){
        mn[i] = mn[2*i];
        mnind[i] = mnind[2*i];
      }
      else{
        mn[i] = mn[2*i+1];
        mnind[i] = mnind[2*i+1];
      }
    }
  }
  inline void build(int a){
    while(a > 1){
      a /= 2;
      sum[a] = sum[a*2] + sum[a*2+1];
      if(mn[a*2] <= mn[a*2+1]){
        mn[a] = mn[a*2];
        mnind[a] = mnind[a*2];
      }
      else{
        mn[a] = mn[a*2+1];
        mnind[a] = mnind[a*2+1];
      }
    }
  }
  inline void change(int a, T val){
    sum[a+N] = mn[a+N] = val;
    build(a+N);
  }
  inline void add(int a, T val){
    sum[a+N] = (mn[a+N] += val);
    build(a+N);
  }
  inline pair<T,int> getMin(int a, int b){
    pair<T,int> res;
    pair<T,int> tmp;
    int fga = 0;
    int fgb = 0;
    a += N;
    b += N;
    while(a < b){
      if(a%2){
        if(fga){
          res =min_L(res, make_pair(mn[a], mnind[a]));
        }
        else{
          res = make_pair(mn[a], mnind[a]);
          fga = 1;
        }
        a++;
      }
      if(b%2){
        b--;
        if(fgb){
          tmp =min_L(make_pair(mn[b], mnind[b]), tmp);
        }
        else{
          tmp = make_pair(mn[b], mnind[b]);
          fgb = 1;
        }
      }
      a /= 2;
      b /= 2;
    }
    if(fga==1 && fgb==0){
      return res;
    }
    if(fga==0 && fgb==1){
      return tmp;
    }
    if(fga==1 && fgb==1){
      res =min_L(res, tmp);
      return res;
    }
    return res;
  }
  inline T getMinVal(int a, int b){
    T res;
    T tmp;
    int fga = 0;
    int fgb = 0;
    a += N;
    b += N;
    while(a < b){
      if(a%2){
        if(fga){
          res =min_L(res, mn[a]);
        }
        else{
          res = mn[a];
          fga = 1;
        }
        a++;
      }
      if(b%2){
        b--;
        if(fgb){
          tmp =min_L(mn[b], tmp);
        }
        else{
          tmp = mn[b];
          fgb = 1;
        }
      }
      a /= 2;
      b /= 2;
    }
    if(fga==1 && fgb==0){
      return res;
    }
    if(fga==0 && fgb==1){
      return tmp;
    }
    if(fga==1 && fgb==1){
      res =min_L(res, tmp);
      return res;
    }
    return res;
  }
  inline int getMinInd(int a, int b){
    return getMin(a,b).second;
  }
  inline T getSum(int a, int b){
    T res;
    T tmp;
    int fga = 0;
    int fgb = 0;
    a += N;
    b += N;
    while(a < b){
      if(a%2){
        if(fga){
          res = res + sum[a];
        }
        else{
          res = sum[a];
          fga = 1;
        }
        a++;
      }
      if(b%2){
        b--;
        if(fgb){
          tmp = sum[b] + tmp;
        }
        else{
          tmp = sum[b];
          fgb = 1;
        }
      }
      a /= 2;
      b /= 2;
    }
    if(fga==1 && fgb==0){
      return res;
    }
    if(fga==0 && fgb==1){
      return tmp;
    }
    if(fga==1 && fgb==1){
      res = res + tmp;
      return res;
    }
    return res;
  }
}
;
int N;
int M;
int Q;
int S[1000000];
int T[1000000];
int L;
int R;
int res[1000000];
int road_p[1000000];
int road_m[1000000];
Rand rnd;
long long w[1000000];
int rig1[1000000];
int rig2[1000000];
int lef1[1000000];
int lef2[1000000];
segtree_Point_SumMin<long long> t_rig;
segtree_Point_SumMin<long long> t_lef;
int chk_ok(int i){
  if(S[i] < T[i]){
    if(road_m[S[i]]){
      return 0;
    }
    if(road_p[T[i]-1]){
      return 0;
    }
    if(rig1[S[i]]){
      return 0;
    }
    if(rig2[T[i]]){
      return 0;
    }
    if(t_rig.getSum(S[i]+1,T[i]) != 0){
      return 0;
    }
  }
  else{
    if(road_m[S[i]-1]){
      return 0;
    }
    if(road_p[T[i]]){
      return 0;
    }
    if(lef1[S[i]]){
      return 0;
    }
    if(lef2[T[i]]){
      return 0;
    }
    if(t_lef.getSum(T[i]+1,S[i]) != 0){
      return 0;
    }
  }
  return 1;
}
void do_add(int i){
  if(S[i] < T[i]){
    road_p[S[i]]++;
    road_m[T[i]-1]++;
    rig1[S[i]]++;
    rig2[T[i]]++;
    t_rig.add(S[i], w[i]);
    t_rig.add(T[i], -w[i]);
  }
  else{
    road_p[S[i]-1]++;
    road_m[T[i]]++;
    lef1[S[i]]++;
    lef2[T[i]]++;
    t_lef.add(S[i], w[i]);
    t_lef.add(T[i], -w[i]);
  }
}
void do_del(int i){
  if(S[i] < T[i]){
    road_p[S[i]]--;
    road_m[T[i]-1]--;
    rig1[S[i]]--;
    rig2[T[i]]--;
    t_rig.add(S[i], -w[i]);
    t_rig.add(T[i], w[i]);
  }
  else{
    road_p[S[i]-1]--;
    road_m[T[i]]--;
    lef1[S[i]]--;
    lef2[T[i]]--;
    t_lef.add(S[i], -w[i]);
    t_lef.add(T[i], w[i]);
  }
}
int main(){
  int QAAnbtfa, QBN4sCMC;
  wmem = memarr;
  int i;
  int j;
  int k;
  rd(N);
  rd(M);
  rd(Q);
  {
    int Nzj9Y0kE;
    for(Nzj9Y0kE=(0);Nzj9Y0kE<(M);Nzj9Y0kE++){
      rd(S[Nzj9Y0kE]);S[Nzj9Y0kE] += (-1);
      rd(T[Nzj9Y0kE]);T[Nzj9Y0kE] += (-1);
    }
  }
  for(QAAnbtfa=(0);QAAnbtfa<(20);QAAnbtfa++){
    rnd.getUni();
  }
  for(i=(0);i<(M);i++){
    w[i] = rnd.get(100LL, 1000000000000LL);
  }
  t_rig.walloc(N+5, 1);
  t_lef.walloc(N+5, 1);
  j = 0;
  for(i=(0);i<(M);i++){
    res[i] = -1;
    if(i){
      res[i] = res[i-1];
    }
    while(j < M && chk_ok(j)){
      do_add(j);
      res[i] = j++;
    }
    do_del(i);
  }
  for(QBN4sCMC=(0);QBN4sCMC<(Q);QBN4sCMC++){
    rd(L);L += (-1);
    rd(R);R += (-1);
    if(res[L] >= R){
      wt_L("Yes");
      wt_L('\n');
    }
    else{
      wt_L("No");
      wt_L('\n');
    }
  }
  return 0;
}
template<class T> inline void wt_L(const vector<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T> inline void wt_L(const set<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T> inline void wt_L(const multiset<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T1, class T2> inline void wt_L(const pair<T1,T2> x){
  wt_L(x.first);
  my_putchar_unlocked(' ');
  wt_L(x.second);
}
// cLay version 20250308-1

// --- original code ---
// int N, M, Q;
// int S[1d6], T[1d6], L, R;
// 
// int res[1d6];
// int road_p[1d6], road_m[1d6];
// Rand rnd;
// ll w[1d6];
// 
// int rig1[1d6], rig2[1d6];
// int lef1[1d6], lef2[1d6];
// 
// segtree_Point_SumMin<ll> t_rig, t_lef;
// 
// int chk_ok(int i){
//   if(S[i] < T[i]){
//     if(road_m[S[i]]) return 0;
//     if(road_p[T[i]-1]) return 0;
//     if(rig1[S[i]]) return 0;
//     if(rig2[T[i]]) return 0;
//     if(t_rig.getSum(S[i]+1,T[i]) != 0) return 0;
//   } else {
//     if(road_m[S[i]-1]) return 0;
//     if(road_p[T[i]]) return 0;
//     if(lef1[S[i]]) return 0;
//     if(lef2[T[i]]) return 0;
//     if(t_lef.getSum(T[i]+1,S[i]) != 0) return 0;
//   }
//   return 1;
// }
// 
// void do_add(int i){
//   if(S[i] < T[i]){
//     road_p[S[i]]++;
//     road_m[T[i]-1]++;
//     rig1[S[i]]++;
//     rig2[T[i]]++;
//     t_rig.add(S[i], w[i]);
//     t_rig.add(T[i], -w[i]);
//   } else {
//     road_p[S[i]-1]++;
//     road_m[T[i]]++;
//     lef1[S[i]]++;
//     lef2[T[i]]++;
//     t_lef.add(S[i], w[i]);
//     t_lef.add(T[i], -w[i]);
//   }
// }
// 
// void do_del(int i){
//   if(S[i] < T[i]){
//     road_p[S[i]]--;
//     road_m[T[i]-1]--;
//     rig1[S[i]]--;
//     rig2[T[i]]--;
//     t_rig.add(S[i], -w[i]);
//     t_rig.add(T[i], w[i]);
//   } else {
//     road_p[S[i]-1]--;
//     road_m[T[i]]--;
//     lef1[S[i]]--;
//     lef2[T[i]]--;
//     t_lef.add(S[i], -w[i]);
//     t_lef.add(T[i], w[i]);
//   }
// }
// 
// {
//   int i, j, k;
//   rd(N,M,Q,(S--,T--)(M));
// 
//   rep(20) rnd.getUni();
//   rep(i,M) w[i] = rnd.get(100LL, 1d12);
// 
//   t_rig.walloc(N+5, 1);
//   t_lef.walloc(N+5, 1);
// 
//   j = 0;
//   rep(i,M){
//     res[i] = -1;
//     if(i) res[i] = res[i-1];
//     while(j < M && chk_ok(j)){
//       do_add(j);
//       res[i] = j++;
//     }
//     do_del(i);
//   }
// 
// 
//   // rep(i,M) wt(i, res[i]);
// 
//   rep(Q){
//     rd(L--, R--);
//     wt(if[res[L] >= R, "Yes", "No"]);
//   }
// }

Submission Info

Submission Time
Task D - Roadway
User LayCurse
Language C++ 23 (gcc 12.2)
Score 900
Code Size 12714 Byte
Status AC
Exec Time 202 ms
Memory 58464 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:488:7: warning: unused variable ‘k’ [-Wunused-variable]
  488 |   int k;
      |       ^
Main.cpp: In function ‘int chk_ok(int)’:
Main.cpp:441:5: warning: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  441 |     if(t_lef.getSum(T[i]+1,S[i]) != 0){
      |     ^~
Main.cpp:348:7: note: ‘res’ was declared here
  348 |     T res;
      |       ^~~
In member function ‘T segtree_Point_SumMin<T>::getSum(int, int) [with T = long long int]’,
    inlined from ‘int chk_ok(int)’ at Main.cpp:441:20:
Main.cpp:385:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
  385 |       res = res + tmp;
      |       ~~~~^~~~~~~~~~~
Main.cpp: In function ‘int chk_ok(int)’:
Main.cpp:349:7: note: ‘tmp’ was declared here
  349 |     T tmp;
      |       ^~~
Main.cpp:424:5: warning: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  424 |     if(t_rig.getSum(S[i]+1,T[i]) != 0){
      |     ^~
Main.cpp:348:7: note: ‘res’ was declared here
  348 |     T res;
      |       ^~~
In member function ‘T segtree_Point_SumMin<T>::getSum(int, int) [with T = long long int]’,
    inlined from ‘int chk_ok(int)’ at Main.cpp:424:20:
Main.cpp:385:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
  385 |       res = res + tmp;
      |       ~~~~^~~~~~~~~~~
Main.cpp: In function ‘int chk_ok(int)’:
Main.cpp:349:7: note: ‘tmp’ was declared here
  349 |     T tmp;
      |       ^~~
In function ‘int chk_ok(int)’,
    inlined from ‘int main()’ at Main.cpp:513:26:
Main.cpp:441:5: warning: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  441 |     if(t_lef.getSum(T[i]+1,S[i]) != 0){
      |     ^~
Main.cpp: In function ‘int main()’:
Main.cpp:348:7: note: ‘res’ was declared here
  348 |     T res;
      |       ^~~
In member function ‘T segtree_Point_SumMin<T>::getSum(int, int) [with T = long long int]’,
    inlined from ‘int chk_ok(int)’ at Main.cpp:441:20,
    inlined from ‘int main()’ at Main.cpp:513:26:
Main.cpp:385:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
  385 |       res = res + tmp;
      |       ~~~~^~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:349:7: note: ‘tmp’ was declared here
  349 |     T tmp;
      |       ^~~
In function ‘int chk_ok(int)’,
    inlined from ‘int main()’ at Main.cpp:513:26:
Main.cpp:424:5: warning: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  424 |     if(t_rig.getSum(S[i]+1,T[i]) != 0){
      |     ^~
Main.cpp: In function ‘int main()’:
Main.cpp:348:7: note: ‘res’ was declared here
  348 |     T res;
      |       ^~~
In member function ‘T segtree_Point_SumMin<T>::getSum(int, int) [with T = long long int]’,
    inlined from ‘int chk_ok(int)’ at Main.cpp:424:20,
    inlined from ‘int main()’ at Main.cpp:513:26:
Main.cpp:385:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
  385 |       res = res + tmp;
      |       ~~~~^~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:349:7: note: ‘tmp’ was declared here
  349 |     T tmp;
      |       ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 2
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KiB
00_sample_01.txt AC 1 ms 3680 KiB
01_test_00.txt AC 202 ms 58464 KiB
01_test_01.txt AC 122 ms 21144 KiB
01_test_02.txt AC 158 ms 35496 KiB
01_test_03.txt AC 165 ms 35744 KiB
01_test_04.txt AC 132 ms 22372 KiB
01_test_05.txt AC 168 ms 35492 KiB
01_test_06.txt AC 126 ms 21652 KiB
01_test_07.txt AC 115 ms 15804 KiB
01_test_08.txt AC 123 ms 21220 KiB
01_test_09.txt AC 156 ms 34600 KiB
01_test_10.txt AC 100 ms 15480 KiB
01_test_11.txt AC 165 ms 57436 KiB
01_test_12.txt AC 137 ms 35280 KiB
01_test_13.txt AC 81 ms 9972 KiB
01_test_14.txt AC 129 ms 32888 KiB
01_test_15.txt AC 140 ms 35636 KiB
01_test_16.txt AC 130 ms 34112 KiB
01_test_17.txt AC 130 ms 33636 KiB
01_test_18.txt AC 170 ms 58428 KiB
01_test_19.txt AC 142 ms 35148 KiB
01_test_20.txt AC 4 ms 4956 KiB
01_test_21.txt AC 4 ms 4968 KiB
01_test_22.txt AC 5 ms 4972 KiB
01_test_23.txt AC 6 ms 5212 KiB
01_test_24.txt AC 65 ms 9112 KiB
01_test_25.txt AC 71 ms 9288 KiB
01_test_26.txt AC 93 ms 53348 KiB
01_test_27.txt AC 61 ms 55292 KiB
01_test_28.txt AC 85 ms 55292 KiB