제출 #1283262

#제출 시각아이디문제언어결과실행 시간메모리
1283262repmannJoker (BOI20_joker)C++20
25 / 100
53 ms9800 KiB
#include <bits/stdc++.h>
using namespace std;
int N, M, K, Q;
int U[200001], V[200001];
int L[200001], R[200001], O[200001];
int END[200001];
struct Node
{
  int p, r;
  bool w;
}DSU[200001];
bool bipartite;
struct Delta
{
  int i;
  Node u;
  bool b;
}D[400001];
int pos;
vector <int> ST[800001];
inline void Rollback(int pos0)
{
  while(pos > pos0)
  {
    bipartite = D[pos].b;
    DSU[D[pos].i] = D[pos].u;
    pos--;
  }
  return;
}
inline int Find(int u)
{
  while(u != DSU[u].p) u = DSU[u].p;
  return u;
}
inline bool Path(int u)
{
  bool w = 0;
  while(u != DSU[u].p) {w ^= DSU[u].w; u = DSU[u].p;}
  return w;
}
inline void Union(int u, int v)
{
  bool uw = Path(u);
  u = Find(u);
  bool vw = Path(v);
  v = Find(v);
  if(u == v)
  {
    if(bipartite && (uw == vw)) {D[++pos] = {0, 0, 1}; bipartite = 0;}
    return;
  }
  if(DSU[u].r < DSU[v].r) swap(u, v);
  if(DSU[u].r == DSU[v].r)
  {
    D[++pos] = {u, DSU[u], bipartite};
    DSU[u].r++;
  }
  D[++pos] = {v, DSU[v], bipartite};
  DSU[v].p = u;
  DSU[v].w = uw ^ vw ^ 1;
  return;
}
inline void Insert(int L, int R, int X, int i = 1, int LC = 1, int RC = K)
{
  if((LC > R) || (L > RC)) return;
  if((L <= LC) && (RC <= R)) {ST[i].push_back(X); return;}
  int S = (LC + RC) >> 1;
  Insert(L, R, X, i << 1, LC, S);
  Insert(L, R, X, i << 1 | 1, S + 1, RC);
  return;
}
inline void Setup()
{
  pos = 0;
  bipartite = 1;
  for(int i = 1; i <= N; i++) DSU[i] = {i, 0, 0};
  K = 1;
  while(K < M) K <<= 1;
  for(int i = 1; i < (K + M); i++) ST[i] = vector <int>();
  for(int i = 1; i <= M; i++) END[i] = M + 1;
  for(int i = 1, j = 1; i <= M; i++)
  {
    if(L[i] > R[i]) break;
    int S = (L[i] + R[i]) >> 1;
    while(j < S) {END[j] = i; j++;}
  }
  for(int i = 1; i <= M; i++) if(L[i] <= R[i]) Insert(i, M, i);
  for(int i = 1; i <= M; i++) if(END[i] > 1) Insert(1, END[i] - 1, i);
  return;
}
inline void DFS(int i = 1, int LC = 1, int RC = K)
{
  if(L[LC] > R[LC]) return;
  int pos0 = pos;
//  cout << i << ":\n";
//  for(int x : ST[i]) cout << x << '\n';
  for(int x : ST[i]) Union(U[x], V[x]);
  if(i >= K)
  {
    int S = (L[LC] + R[LC]) >> 1;
    if(!bipartite) {L[LC] = S + 1; O[LC] = S;}
    else R[LC] = S - 1;
  }
  else
  {
    int S = (LC + RC) >> 1;
    DFS(i << 1, LC, S);
    DFS(i << 1 | 1, S + 1, RC);
  }
  Rollback(pos0);
  return;
}
int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M >> Q;
  for(int i = 1; i <= M; i++) cin >> U[i] >> V[i];
  bipartite = 1;
  for(int i = 1; i <= N; i++) DSU[i] = {i, 0, 0};
  for(int i = M; i >= 1; i--)
  {
    Union(U[i], V[i]);
    if(!bipartite) {O[0] = i; break;}
  }
//  for(int i = 1; i <= M; i++) {L[i] = i; R[i] = M;}
//  while(L[1] <= R[1])
//  {
////    for(int i = 1; i <= M; i++)
////    {
////      int S = (L[i] + R[i]) >> 1;
////      cout << i << ": " << L[i] << ' ' << S << ' ' << R[i] << '\n';
////    }
//    Setup();
////    for(int i = 1; i <= M; i++) cout << i << ": " << END[i] << '\n';
//    DFS();
////    for(int i = 1; i <= M; i++)
////    {
////      int S = (L[i] + R[i]) >> 1;
////      cout << i << ": " << L[i] << ' ' << S << ' ' << R[i] << ' ' << O[i] << '\n';
////    }
//  }
////  for(int i = 0; i <= M; i++) cout << i << ": " << O[i] << '\n';
  int l, r;
  for(int i = 1; i <= Q; i++)
  {
    cin >> l >> r;
    if((r + 1) <= O[l - 1]) cout << "YES\n";
    else cout << "NO\n";
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...