Submission #1094955

# Submission time Handle Problem Language Result Execution time Memory
1094955 2024-10-01T03:26:12 Z ntdaccode Joker (BOI20_joker) C++17
100 / 100
245 ms 24132 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int 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;
int n,m,q;
int x[M],y[M];
//
int id[M],lz[M];
int finded(int u,int &v)
{
  v^=lz[u];
  return id[u]<0 ? u : finded(id[u],v);
}
#define tp tuple<int,int,int>
stack<tp> sk[2];
stack<tp> ks[2];
bool unioned(int u,int v,int mid,int tt)
{
  int x=0;
  int y=0;
  u=finded(u,x);
  v=finded(v,y);
  //if(mid==6) cout << u << " " << v << " " << x << " " << y << "\n";
  if(u==v)
  {
    if(x==y) return true;
    return false;
  }
  if(id[u]>id[v]) swap(u,v);
  sk[tt].push({u,v,mid});
  ks[tt].push({id[u],id[v],lz[v]});
  id[u]+=id[v]; id[v]=u; if(x==y) lz[v]^=1;
  return false;
}
void rollback(int tt,int midl)
{
    while(sk[tt].size())
    {
      auto[u,v,mid]=sk[tt].top();
      if(mid!=midl) break;
      sk[tt].pop();
      auto[idu,idv,lzz]=ks[tt].top();
      ks[tt].pop();
      id[u]=idu;
      id[v]=idv;
      lz[v]=lzz;
    }
}
//
int last[M];
void solve(int l1,int l2,int r1,int r2,bool okk)
{
  if(l1>l2) return ;
  int mid=(l1+l2)/2;
  bool ok=okk;
//      cout << mid << "\n";
//    cout << l1 << " " << l2 << " " << r1 << " " << r2  << " " << sk[1].size() <<  "\n";
//      fori(i,1,n) cout << id[i] << " ";
//      cout << endl;

  fori(i,l1,mid-1)
  {
    if(unioned(x[i],y[i],mid,0)) ok=1;
  }
  bool tmpok=ok;
  int opt=r2;
  if(!ok)
  for(int i=r2;i>=max(r1,mid);i--)
  {
    if(unioned(x[i],y[i],mid,1)) ok=1;
    if(ok)
    {
      opt=i;
      break;
    }
  }
  if(ok) last[mid]=(tmpok&&r2==m ? m+1 : opt);
//    cout << mid << "\n";
//    cout << okk << " " << l1 << " " << l2 << " " << r1 << " " << r2 << " " << last[mid] <<  "\n";
//      fori(i,1,n) cout << id[i] << " ";
//      cout << endl;

  if(l1!=l2)
  {
  rollback(1,mid);
  if(unioned(x[mid],y[mid],mid,0)) tmpok=1;
  solve(mid+1,l2,opt,r2,tmpok);
  ok=okk;
  rollback(0,mid);
  for(int i=r2;i>opt;i--)
  {
    if( unioned(x[i],y[i],mid,1)) ok=1;
  }
  solve(l1,mid-1,r1,opt,ok);
  }
  rollback(1,mid);
}
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,n) id[i]=last[i]=-1;
  solve(1,m,1,m,0);
  //fori(i,1,n) cout << last[i] << " ";
  while(q--)
  {
    int l,r;
    cin >> l >> r;
    if(r<last[l]) cout << "YES\n";
    else cout << "NO\n";
  }
}


Compilation message

Joker.cpp: In function 'int32_t main()':
Joker.cpp:113:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:114:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 472 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 0 ms 360 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 472 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 0 ms 360 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 496 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 1 ms 628 KB Output is correct
37 Correct 3 ms 616 KB Output is correct
38 Correct 2 ms 616 KB Output is correct
39 Correct 1 ms 616 KB Output is correct
40 Correct 1 ms 616 KB Output is correct
41 Correct 1 ms 616 KB Output is correct
42 Correct 1 ms 616 KB Output is correct
43 Correct 1 ms 500 KB Output is correct
44 Correct 1 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 1 ms 652 KB Output is correct
48 Correct 1 ms 616 KB Output is correct
49 Correct 1 ms 616 KB Output is correct
50 Correct 1 ms 616 KB Output is correct
51 Correct 1 ms 616 KB Output is correct
52 Correct 1 ms 616 KB Output is correct
53 Correct 2 ms 680 KB Output is correct
54 Correct 2 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 142 ms 16260 KB Output is correct
4 Correct 236 ms 21004 KB Output is correct
5 Correct 116 ms 19284 KB Output is correct
6 Correct 121 ms 16292 KB Output is correct
7 Correct 127 ms 16404 KB Output is correct
8 Correct 133 ms 13248 KB Output is correct
9 Correct 151 ms 15048 KB Output is correct
10 Correct 210 ms 19024 KB Output is correct
11 Correct 143 ms 15620 KB Output is correct
12 Correct 176 ms 18260 KB Output is correct
13 Correct 114 ms 10808 KB Output is correct
14 Correct 139 ms 13476 KB Output is correct
15 Correct 204 ms 16692 KB Output is correct
16 Correct 208 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 472 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 0 ms 360 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
29 Correct 142 ms 16260 KB Output is correct
30 Correct 236 ms 21004 KB Output is correct
31 Correct 116 ms 19284 KB Output is correct
32 Correct 121 ms 16292 KB Output is correct
33 Correct 127 ms 16404 KB Output is correct
34 Correct 133 ms 13248 KB Output is correct
35 Correct 151 ms 15048 KB Output is correct
36 Correct 210 ms 19024 KB Output is correct
37 Correct 143 ms 15620 KB Output is correct
38 Correct 176 ms 18260 KB Output is correct
39 Correct 114 ms 10808 KB Output is correct
40 Correct 139 ms 13476 KB Output is correct
41 Correct 204 ms 16692 KB Output is correct
42 Correct 208 ms 19028 KB Output is correct
43 Correct 135 ms 16640 KB Output is correct
44 Correct 245 ms 21020 KB Output is correct
45 Correct 201 ms 22880 KB Output is correct
46 Correct 116 ms 16716 KB Output is correct
47 Correct 122 ms 16592 KB Output is correct
48 Correct 169 ms 15472 KB Output is correct
49 Correct 220 ms 19024 KB Output is correct
50 Correct 137 ms 14908 KB Output is correct
51 Correct 166 ms 17216 KB Output is correct
52 Correct 188 ms 19284 KB Output is correct
53 Correct 121 ms 11096 KB Output is correct
54 Correct 160 ms 15052 KB Output is correct
55 Correct 193 ms 17108 KB Output is correct
56 Correct 220 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 472 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 0 ms 360 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 496 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 1 ms 628 KB Output is correct
37 Correct 3 ms 616 KB Output is correct
38 Correct 2 ms 616 KB Output is correct
39 Correct 1 ms 616 KB Output is correct
40 Correct 1 ms 616 KB Output is correct
41 Correct 1 ms 616 KB Output is correct
42 Correct 1 ms 616 KB Output is correct
43 Correct 1 ms 500 KB Output is correct
44 Correct 1 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 1 ms 652 KB Output is correct
48 Correct 1 ms 616 KB Output is correct
49 Correct 1 ms 616 KB Output is correct
50 Correct 1 ms 616 KB Output is correct
51 Correct 1 ms 616 KB Output is correct
52 Correct 1 ms 616 KB Output is correct
53 Correct 2 ms 680 KB Output is correct
54 Correct 2 ms 616 KB Output is correct
55 Correct 108 ms 13920 KB Output is correct
56 Correct 217 ms 20896 KB Output is correct
57 Correct 100 ms 19232 KB Output is correct
58 Correct 102 ms 14040 KB Output is correct
59 Correct 139 ms 13620 KB Output is correct
60 Correct 180 ms 16988 KB Output is correct
61 Correct 133 ms 13548 KB Output is correct
62 Correct 152 ms 18068 KB Output is correct
63 Correct 110 ms 10168 KB Output is correct
64 Correct 158 ms 14740 KB Output is correct
65 Correct 190 ms 18100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 472 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 472 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 0 ms 360 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 2 ms 688 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 496 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 616 KB Output is correct
36 Correct 1 ms 628 KB Output is correct
37 Correct 3 ms 616 KB Output is correct
38 Correct 2 ms 616 KB Output is correct
39 Correct 1 ms 616 KB Output is correct
40 Correct 1 ms 616 KB Output is correct
41 Correct 1 ms 616 KB Output is correct
42 Correct 1 ms 616 KB Output is correct
43 Correct 1 ms 500 KB Output is correct
44 Correct 1 ms 616 KB Output is correct
45 Correct 2 ms 616 KB Output is correct
46 Correct 2 ms 616 KB Output is correct
47 Correct 1 ms 652 KB Output is correct
48 Correct 1 ms 616 KB Output is correct
49 Correct 1 ms 616 KB Output is correct
50 Correct 1 ms 616 KB Output is correct
51 Correct 1 ms 616 KB Output is correct
52 Correct 1 ms 616 KB Output is correct
53 Correct 2 ms 680 KB Output is correct
54 Correct 2 ms 616 KB Output is correct
55 Correct 142 ms 16260 KB Output is correct
56 Correct 236 ms 21004 KB Output is correct
57 Correct 116 ms 19284 KB Output is correct
58 Correct 121 ms 16292 KB Output is correct
59 Correct 127 ms 16404 KB Output is correct
60 Correct 133 ms 13248 KB Output is correct
61 Correct 151 ms 15048 KB Output is correct
62 Correct 210 ms 19024 KB Output is correct
63 Correct 143 ms 15620 KB Output is correct
64 Correct 176 ms 18260 KB Output is correct
65 Correct 114 ms 10808 KB Output is correct
66 Correct 139 ms 13476 KB Output is correct
67 Correct 204 ms 16692 KB Output is correct
68 Correct 208 ms 19028 KB Output is correct
69 Correct 135 ms 16640 KB Output is correct
70 Correct 245 ms 21020 KB Output is correct
71 Correct 201 ms 22880 KB Output is correct
72 Correct 116 ms 16716 KB Output is correct
73 Correct 122 ms 16592 KB Output is correct
74 Correct 169 ms 15472 KB Output is correct
75 Correct 220 ms 19024 KB Output is correct
76 Correct 137 ms 14908 KB Output is correct
77 Correct 166 ms 17216 KB Output is correct
78 Correct 188 ms 19284 KB Output is correct
79 Correct 121 ms 11096 KB Output is correct
80 Correct 160 ms 15052 KB Output is correct
81 Correct 193 ms 17108 KB Output is correct
82 Correct 220 ms 19028 KB Output is correct
83 Correct 108 ms 13920 KB Output is correct
84 Correct 217 ms 20896 KB Output is correct
85 Correct 100 ms 19232 KB Output is correct
86 Correct 102 ms 14040 KB Output is correct
87 Correct 139 ms 13620 KB Output is correct
88 Correct 180 ms 16988 KB Output is correct
89 Correct 133 ms 13548 KB Output is correct
90 Correct 152 ms 18068 KB Output is correct
91 Correct 110 ms 10168 KB Output is correct
92 Correct 158 ms 14740 KB Output is correct
93 Correct 190 ms 18100 KB Output is correct
94 Correct 129 ms 17288 KB Output is correct
95 Correct 173 ms 22528 KB Output is correct
96 Correct 111 ms 19324 KB Output is correct
97 Correct 120 ms 17372 KB Output is correct
98 Correct 124 ms 17388 KB Output is correct
99 Correct 141 ms 14548 KB Output is correct
100 Correct 189 ms 19420 KB Output is correct
101 Correct 138 ms 15768 KB Output is correct
102 Correct 176 ms 16884 KB Output is correct
103 Correct 204 ms 19024 KB Output is correct
104 Correct 143 ms 13380 KB Output is correct
105 Correct 205 ms 17396 KB Output is correct
106 Correct 219 ms 18920 KB Output is correct
107 Correct 113 ms 24132 KB Output is correct
108 Correct 141 ms 17100 KB Output is correct
109 Correct 131 ms 17036 KB Output is correct
110 Correct 131 ms 17028 KB Output is correct
111 Correct 137 ms 17020 KB Output is correct
112 Correct 137 ms 17100 KB Output is correct
113 Correct 148 ms 17180 KB Output is correct
114 Correct 138 ms 17100 KB Output is correct
115 Correct 136 ms 16972 KB Output is correct
116 Correct 138 ms 17036 KB Output is correct