Submission #1093727

# Submission time Handle Problem Language Result Execution time Memory
1093727 2024-09-27T10:40:05 Z ntdaccode Joker (BOI20_joker) C++17
71 / 100
2000 ms 15440 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=2e5+10;
const int N=1e3+10;
const int SIZE=448;
int n,m,q;
int x[M],y[M];
struct query
{
  int l,r,idx;
}Q[M];
int ret[M];
// dsu
int id[M];
bool dd[M],lz[M];
#define tp tuple<int,int,int>
stack<tp> sk;
stack<tp> ks;
int finded(int u,bool &v)
{
  v^=lz[u];
  return id[u] < 0 ? u : finded(id[u],v);
}
bool unioned(int tt ,int u,int v)
{
  bool pos=0,pos2=0;
  u=finded(u,pos);
  v=finded(v,pos2);

  if(u==v)
  {
    if(pos==pos2) return true;
    return false;
  }
  if(id[u]>id[v]) swap(u,v);
  if(tt!=0)
  {
  sk.push({tt,id[u],id[v]});
  ks.push({pos==pos2,u,v});
  }
  if(pos==pos2) lz[v]^=1;
  id[u]+=id[v];
  id[v]=u;
  return false;
}
void rollback(int ok)
{
      while(!sk.empty())
      {
        auto[tt,idu,idv] = sk.top();
        auto[tt2,u,v] = ks.top();
        if(tt==ok) break;
        sk.pop(); ks.pop();
        lz[v]^=tt2;
        id[u]=idu; id[v]=idv;
      }
}
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;
  bool okk=0;
  fori(i,1,q)
  {
    if(ok)
    {
      ret[Q[i].idx]=1;
      continue;
    }

    int cur=(Q[i].l/SIZE)*SIZE;
    if(Q[i-1].l/SIZE!=Q[i].l/SIZE)
    {
      rollback(0);
      okk=0;
      fori(j,max(1,(Q[i-1].l/SIZE)*SIZE),cur-1)
      if(unioned(0,x[j],y[j]))
      {
        ok=1;
        break;
      }
      r=m;
    }
    if(ok)
    {
      ret[Q[i].idx]=1;
      continue;
    }

    while(Q[i].r<r&&r!=cur)
    {
      if(x[r]==y[r]) continue;
      if(unioned(1,x[r],y[r]))
      {
        okk=1;
        break;
      }
      r--;
    }



    if(okk) ret[Q[i].idx]=1;
    else
    {

      bool ook=0;
      fori(j,max(1,cur),Q[i].l-1)
      {
        if(unioned(2,x[j],y[j]))
        {
          ook=1;
          break;
        }
      }
      fori(j,Q[i].r+1,r)
      {
        if(unioned(2,x[j],y[j]))
        {
          ook=1;
          break;
        }
      }
      rollback(1);
      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:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1028 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1028 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 9 ms 1212 KB Output is correct
30 Correct 5 ms 1304 KB Output is correct
31 Correct 4 ms 1372 KB Output is correct
32 Correct 3 ms 1352 KB Output is correct
33 Correct 2 ms 1352 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
35 Correct 5 ms 1372 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 10 ms 1372 KB Output is correct
38 Correct 10 ms 1300 KB Output is correct
39 Correct 8 ms 1372 KB Output is correct
40 Correct 4 ms 1244 KB Output is correct
41 Correct 4 ms 1372 KB Output is correct
42 Correct 4 ms 1368 KB Output is correct
43 Correct 1 ms 1120 KB Output is correct
44 Correct 2 ms 1376 KB Output is correct
45 Correct 2 ms 1376 KB Output is correct
46 Correct 2 ms 1376 KB Output is correct
47 Correct 4 ms 1248 KB Output is correct
48 Correct 4 ms 1376 KB Output is correct
49 Correct 5 ms 1376 KB Output is correct
50 Correct 4 ms 1380 KB Output is correct
51 Correct 4 ms 1372 KB Output is correct
52 Correct 4 ms 1368 KB Output is correct
53 Correct 5 ms 1372 KB Output is correct
54 Correct 5 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 66 ms 12876 KB Output is correct
4 Correct 68 ms 14332 KB Output is correct
5 Correct 58 ms 11252 KB Output is correct
6 Correct 59 ms 12908 KB Output is correct
7 Correct 62 ms 13064 KB Output is correct
8 Correct 69 ms 11256 KB Output is correct
9 Correct 59 ms 12116 KB Output is correct
10 Correct 64 ms 12856 KB Output is correct
11 Correct 65 ms 12688 KB Output is correct
12 Correct 64 ms 13208 KB Output is correct
13 Correct 60 ms 10832 KB Output is correct
14 Correct 59 ms 11856 KB Output is correct
15 Correct 64 ms 12948 KB Output is correct
16 Correct 64 ms 13280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1028 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 66 ms 12876 KB Output is correct
30 Correct 68 ms 14332 KB Output is correct
31 Correct 58 ms 11252 KB Output is correct
32 Correct 59 ms 12908 KB Output is correct
33 Correct 62 ms 13064 KB Output is correct
34 Correct 69 ms 11256 KB Output is correct
35 Correct 59 ms 12116 KB Output is correct
36 Correct 64 ms 12856 KB Output is correct
37 Correct 65 ms 12688 KB Output is correct
38 Correct 64 ms 13208 KB Output is correct
39 Correct 60 ms 10832 KB Output is correct
40 Correct 59 ms 11856 KB Output is correct
41 Correct 64 ms 12948 KB Output is correct
42 Correct 64 ms 13280 KB Output is correct
43 Correct 338 ms 13396 KB Output is correct
44 Correct 405 ms 14672 KB Output is correct
45 Correct 392 ms 15440 KB Output is correct
46 Correct 332 ms 13396 KB Output is correct
47 Correct 308 ms 13292 KB Output is correct
48 Correct 95 ms 12628 KB Output is correct
49 Correct 137 ms 13396 KB Output is correct
50 Correct 247 ms 12612 KB Output is correct
51 Correct 339 ms 13264 KB Output is correct
52 Correct 389 ms 13344 KB Output is correct
53 Correct 175 ms 11092 KB Output is correct
54 Correct 439 ms 12504 KB Output is correct
55 Correct 425 ms 13388 KB Output is correct
56 Correct 462 ms 13564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1028 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 9 ms 1212 KB Output is correct
30 Correct 5 ms 1304 KB Output is correct
31 Correct 4 ms 1372 KB Output is correct
32 Correct 3 ms 1352 KB Output is correct
33 Correct 2 ms 1352 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
35 Correct 5 ms 1372 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 10 ms 1372 KB Output is correct
38 Correct 10 ms 1300 KB Output is correct
39 Correct 8 ms 1372 KB Output is correct
40 Correct 4 ms 1244 KB Output is correct
41 Correct 4 ms 1372 KB Output is correct
42 Correct 4 ms 1368 KB Output is correct
43 Correct 1 ms 1120 KB Output is correct
44 Correct 2 ms 1376 KB Output is correct
45 Correct 2 ms 1376 KB Output is correct
46 Correct 2 ms 1376 KB Output is correct
47 Correct 4 ms 1248 KB Output is correct
48 Correct 4 ms 1376 KB Output is correct
49 Correct 5 ms 1376 KB Output is correct
50 Correct 4 ms 1380 KB Output is correct
51 Correct 4 ms 1372 KB Output is correct
52 Correct 4 ms 1368 KB Output is correct
53 Correct 5 ms 1372 KB Output is correct
54 Correct 5 ms 1372 KB Output is correct
55 Correct 365 ms 7672 KB Output is correct
56 Correct 1505 ms 10360 KB Output is correct
57 Correct 50 ms 5828 KB Output is correct
58 Correct 33 ms 7512 KB Output is correct
59 Correct 129 ms 7096 KB Output is correct
60 Correct 313 ms 7764 KB Output is correct
61 Correct 176 ms 7192 KB Output is correct
62 Correct 373 ms 7792 KB Output is correct
63 Correct 45 ms 5848 KB Output is correct
64 Correct 191 ms 6744 KB Output is correct
65 Correct 396 ms 7756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1028 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1232 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 9 ms 1212 KB Output is correct
30 Correct 5 ms 1304 KB Output is correct
31 Correct 4 ms 1372 KB Output is correct
32 Correct 3 ms 1352 KB Output is correct
33 Correct 2 ms 1352 KB Output is correct
34 Correct 3 ms 1372 KB Output is correct
35 Correct 5 ms 1372 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 10 ms 1372 KB Output is correct
38 Correct 10 ms 1300 KB Output is correct
39 Correct 8 ms 1372 KB Output is correct
40 Correct 4 ms 1244 KB Output is correct
41 Correct 4 ms 1372 KB Output is correct
42 Correct 4 ms 1368 KB Output is correct
43 Correct 1 ms 1120 KB Output is correct
44 Correct 2 ms 1376 KB Output is correct
45 Correct 2 ms 1376 KB Output is correct
46 Correct 2 ms 1376 KB Output is correct
47 Correct 4 ms 1248 KB Output is correct
48 Correct 4 ms 1376 KB Output is correct
49 Correct 5 ms 1376 KB Output is correct
50 Correct 4 ms 1380 KB Output is correct
51 Correct 4 ms 1372 KB Output is correct
52 Correct 4 ms 1368 KB Output is correct
53 Correct 5 ms 1372 KB Output is correct
54 Correct 5 ms 1372 KB Output is correct
55 Correct 66 ms 12876 KB Output is correct
56 Correct 68 ms 14332 KB Output is correct
57 Correct 58 ms 11252 KB Output is correct
58 Correct 59 ms 12908 KB Output is correct
59 Correct 62 ms 13064 KB Output is correct
60 Correct 69 ms 11256 KB Output is correct
61 Correct 59 ms 12116 KB Output is correct
62 Correct 64 ms 12856 KB Output is correct
63 Correct 65 ms 12688 KB Output is correct
64 Correct 64 ms 13208 KB Output is correct
65 Correct 60 ms 10832 KB Output is correct
66 Correct 59 ms 11856 KB Output is correct
67 Correct 64 ms 12948 KB Output is correct
68 Correct 64 ms 13280 KB Output is correct
69 Correct 338 ms 13396 KB Output is correct
70 Correct 405 ms 14672 KB Output is correct
71 Correct 392 ms 15440 KB Output is correct
72 Correct 332 ms 13396 KB Output is correct
73 Correct 308 ms 13292 KB Output is correct
74 Correct 95 ms 12628 KB Output is correct
75 Correct 137 ms 13396 KB Output is correct
76 Correct 247 ms 12612 KB Output is correct
77 Correct 339 ms 13264 KB Output is correct
78 Correct 389 ms 13344 KB Output is correct
79 Correct 175 ms 11092 KB Output is correct
80 Correct 439 ms 12504 KB Output is correct
81 Correct 425 ms 13388 KB Output is correct
82 Correct 462 ms 13564 KB Output is correct
83 Correct 365 ms 7672 KB Output is correct
84 Correct 1505 ms 10360 KB Output is correct
85 Correct 50 ms 5828 KB Output is correct
86 Correct 33 ms 7512 KB Output is correct
87 Correct 129 ms 7096 KB Output is correct
88 Correct 313 ms 7764 KB Output is correct
89 Correct 176 ms 7192 KB Output is correct
90 Correct 373 ms 7792 KB Output is correct
91 Correct 45 ms 5848 KB Output is correct
92 Correct 191 ms 6744 KB Output is correct
93 Correct 396 ms 7756 KB Output is correct
94 Correct 741 ms 13544 KB Output is correct
95 Execution timed out 2017 ms 13732 KB Time limit exceeded
96 Halted 0 ms 0 KB -