제출 #561280

#제출 시각아이디문제언어결과실행 시간메모리
561280messiuuuuuJoker (BOI20_joker)C++14
0 / 100
62 ms5676 KiB
#include<bits/stdc++.h> #define task "F" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 2e5 + 5; const ll INF = 1e18 + 5; int n, m, q; pair<int, int> es[MAXN]; void Input() { cin >> n >> m >> q; for (int i = 1; i <= m; i++) cin >> es[i].fi >> es[i].se; } struct TRback { int u, lu, v, lv; }; stack<TRback> Q; int lab[MAXN], f[MAXN]; bool pare[MAXN]; pair<int, int> FindSet(int u) { bool w = 0; while (lab[u] > 0) { w ^= pare[u]; u = lab[u]; } return {u, w}; } bool Unite(int u, int v) { auto pu = FindSet(u); auto pv = FindSet(v); if (pu.fi == pv.fi) { return (pu.se != pv.se); } if (lab[pu.fi] > lab[pv.fi]) swap(pu, pv); u = pu.fi; v = pv.fi; Q.push({u, lab[u], v, lab[v]}); lab[u] += lab[v]; lab[v] = u; pare[v] = pu.se ^ pv.se ^ 1; return 1; } void rollback(int sz) { while (Q.size() > sz) { auto p = Q.top(); Q.pop(); lab[p.u] = p.lu; lab[p.v] = p.lv; } } void Dnc(int l, int r, int pl, int pr) { if (l > r) return; int mid = (l + r) / 2; int s = Q.size(); bool kt = 1; for (int i = l; i <= mid; i++) { if (!Unite(es[i].fi, es[i].se)) { kt = 0; break; } } if (kt) { int s1 = Q.size(); for (int i = min(m, pr); i >= max(mid + 1, pl); i--) { if (!Unite(es[i].fi, es[i].se)) { f[mid] = i; break; } } //if (mid == 1) // cerr << f[mid] << '\n'; rollback(s1); Dnc(mid + 1, r, f[mid], pr); } rollback(s); for (int i = f[mid] + 1; i <= pr; i++) Unite(es[i].fi, es[i].se); Dnc(l, mid - 1, pl, f[mid]); rollback(s); } void Solve() { memset(lab, -1, sizeof(lab)); fill(f + 1, f + 1 + m, m + 1); Dnc(0, m, 1, m + 1); /* for (int i = 1; i <= m; i++) cerr << f[i] << ' '; cerr << '\n'; */ while (q-- > 0) { int l, r; cin >> l >> r; l--; r++; cout << (r <= f[l] ? "YES\n" : "NO\n"); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); Input(); Solve(); }

컴파일 시 표준 에러 (stderr) 메시지

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::stack<TRback>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while (Q.size() > sz)
      |            ~~~~~~~~~^~~~
#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...