Submission #1340912

#TimeUsernameProblemLanguageResultExecution timeMemory
1340912loomJoker (BOI20_joker)C++20
0 / 100
102 ms13532 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)2e18
#define _ <<' '<<
#define nl '\n'

const int N = 2e5;
pair<int,int> ed[N];
vector<array<int,3>> v;
int p[N], sz[N], ans[N];
int n, m, q, tf;

pair<int,int> find(int x){
   if(p[x] == x) return {x, 0};
   
   auto [pr, ds] = find(p[x]);
   return {pr, 1 + ds};
}

void add(int i){
   if(i == m){
      v.push_back({-1, -1, tf});
      return;
   }

   auto [a, b] = ed[i];
   auto [x, dx] = find(a);
   auto [y, dy] = find(b);

   if(x == y){
      v.push_back({-1, -1, tf});
      if((dx + dy) % 2 == 0) tf = 1;
      return;
   }

   if(sz[x] < sz[y]) swap(x, y);

   p[y] = x;
   sz[x] += sz[y];
   v.push_back({x, y, tf});
}

void add(int l, int r){
   for(int i = l; i <= r; i++) add(i);
}

void del(){
   auto [x, y, ptf] = v.back();
   v.pop_back();

   if(x != -1){
      p[y] = y;
      sz[x] -= sz[y];
   }

   tf = ptf;
}

void del(int c){
   for(int i = 0; i < c; i++) del();
}

void dnc(int l, int r, int opl, int opr){
   if(l > r) return;
   int m = (l+r)/2;

   add(l, m-1);
   int opm = opr, c = 0;

   for(int i = opr; i > opl; i--){
      add(i);
      c++;

      if(!tf) opm = i-1;
      else break;
   }

   ans[m] = opm;

   del(c);
   add(m);
   dnc(m+1, r, opm, opr);

   del(m-l+1);
   add(opm+1, opr);
   dnc(l, m-1, opl, opm);

   del(opr - opm);
}

void solve(){
   cin>>n>>m>>q;

   for(int i = 0; i < m; i++){
      int x, y;
      cin>>x>>y;
      x--, y--;

      ed[i] = {x, y};
   }

   iota(p, p + N, 0);
   fill(sz, sz + N, 1);
   
   dnc(0, m-1, 0, m);

   while(q--){
      int l, r;
      cin>>l>>r;
      l--, r--;

      cout<<(ans[l] <= r ? "NO" : "YES")<<nl;
   }
}

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);

   int t = 1;
   //cin>>t;
   while(t--) solve();

   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...