답안 #1093562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093562 2024-09-27T03:39:41 Z ntdaccode Joker (BOI20_joker) C++17
0 / 100
2000 ms 16100 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
const int SIZE=316;
int n,m,q;
int x[M],y[M];
struct query
{
  int l,r,idx;
}Q[M];
int ret[M];
// dsu
int id[M];
int dd[M],lz[M];
#define tp tuple<int,int,int>
stack<tp> sk;
stack<tp> ks;
int finded(int u,int &v)
{
  v=1-lz[u];
  return id[u] < 0 ? u : finded(id[u],v);
}
bool unioned(int tt ,int u,int v)
{
  int pos=0,pos2=0;
  u=finded(u,pos);
  v=finded(v,pos2);
  if(u==v&&pos==pos2) return true;
  if(tt!=0)
  {
  sk.push({tt,id[u],id[v]});
  ks.push({tt,u,v});
  }
  id[u]+=id[v];
  id[v]=u;
  if(pos==pos2) lz[v]=1-lz[v];
  return false;
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> m >> q;
  fori(i,1,m) cin >> x[i] >> y[i];
  fori(i,1,q)
  {
    cin >> Q[i].l >> Q[i].r ;
    Q[i].idx=i;
  }
  sort(Q+1,Q+q+1,[&] (const query a,const query b)
       {
         if(a.l/SIZE==b.l/SIZE) return a.r> b.r;
         return  a.l<b.l;
       });
  memset(id,-1,sizeof(id));
  int r=m;
  bool ok=0;
  int cur=0;
  fori(i,1,q)
  {
    if(Q[i-1].l/SIZE!=Q[i].l/SIZE)
    {
      while(!sk.empty())
      {
        auto[tt,idu,idv] = sk.top();
        auto[tt2,u,v] = ks.top();
        sk.pop();
        ks.pop();
        id[u]=idu;
        id[v]=idv;
      }
      fori(j,max(1,Q[i-1].l*SIZE),(Q[i].l/SIZE)*SIZE-1) if(unioned(0,x[j],y[j])) ok=1;
      r=m;
    }
    bool okk=0;
    while(Q[i].r<=r&&r/SIZE!=Q[i].l/SIZE)
    {
      if(x[r]==y[r]) continue;
      if(unioned(1,x[r],y[r])) okk=1;
      r--;
    }
   // cout << r << " ";
    if(ok||okk) ret[Q[i].idx]=1;
    else
    {
      int ook=0;
      fori(j,max(1,(Q[i].l/SIZE)*SIZE),Q[i].l-1)
      {
        if(x[r]==y[r]) continue;
        if(unioned(2,x[j],y[j])) ook=1;
        //cout << x[j] << " " << y[j] << "\n";
      }
      fori(j,Q[i].r+1,r)
      {
        if(x[r]==y[r]) continue;
        if(unioned(2,x[j],y[j])) ook=1;
        //cout << x[j] << " " << y[j] << "\n";
      }
      while(!sk.empty())
      {
        auto[tt,idu,idv] = sk.top();
        auto[tt2,u,v] = ks.top();
        if(tt!=2) break;
        sk.pop();
        ks.pop();
        id[u]=idu;
        id[v]=idv;
      }
      if(ook) ret[Q[i].idx]=1;
    }
  }
  fori(i,1,q)
  {
    if(ret[i]) cout << "YES\n";
    else cout << "NO\n";
  }
}



Compilation message

Joker.cpp: In function 'int32_t main()':
Joker.cpp:73:7: warning: unused variable 'cur' [-Wunused-variable]
   73 |   int cur=0;
      |       ^~~
Joker.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Incorrect 2 ms 4188 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Incorrect 2 ms 4188 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Execution timed out 2044 ms 16100 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Incorrect 2 ms 4188 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Incorrect 2 ms 4188 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Incorrect 2 ms 4188 KB Output isn't correct
9 Halted 0 ms 0 KB -