제출 #1168076

#제출 시각아이디문제언어결과실행 시간메모리
1168076steveonalexJoker (BOI20_joker)C++20
71 / 100
2093 ms14960 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 2e5 + 69, BLOCK = 500; struct DSU{ int n; array<pair<int, int>, N> parent; array<int, N> sz; int is_valid; DSU(int _n){ n = _n; } void reset(){ for(int i = 1; i <= n; ++i) { parent[i] = {i, 0}; sz[i] = 1; } is_valid = 1; } pair<int, int> find_set(int u){ if (u == parent[u].first) return parent[u]; pair<int, int> v = find_set(parent[u].first); v.second ^= parent[u].second; return parent[u] = v; } bool join_set(int x, int y, int w){ pair<int, int> u = find_set(x), v = find_set(y); if (u.first != v.first){ if (sz[u.first] < sz[v.first]) swap(u, v); parent[v.first] = make_pair(u.first, u.second ^ v.second ^ w); sz[u.first] += sz[v.first]; return true; } if (u.second ^ v.second ^ w) is_valid = 0; return false; } }; int n, m, q; pair<int, int> edge[N]; pair<int, int> queries[N]; vector<int> queries_list[N]; bool ans[N]; DSU mst(N-1); DSU outer(N-1); void solve(){ cin >> n >> m >> q; for(int i = 0; i < m; ++i){ cin >> edge[i].first >> edge[i].second; } for(int i = 0; i < q; ++i){ int l, r; cin >> l >> r; l--; r--; queries[i] = {l, r}; queries_list[l / BLOCK].push_back(i); } for(int i = 0; i <= m / BLOCK; ++i) if (queries_list[i].size()){ sort(ALL(queries_list[i]), [](int x, int y){return queries[x].second < queries[y].second;}); mst.reset(); outer.reset(); for(int j = 0; j < i * BLOCK; ++j) mst.join_set(edge[j].first, edge[j].second, 1); int r = m-1; while(queries_list[i].size()){ int j = queries_list[i].back(); queries_list[i].pop_back(); while(r > queries[j].second){ mst.join_set(edge[r].first, edge[r].second, 1); r--; } if (mst.is_valid == false) continue; for(int t = i * BLOCK; t < queries[j].first; ++t){ pair<int,int> u = mst.find_set(edge[t].first), v = mst.find_set(edge[t].second); outer.join_set(u.first, v.first, 1 ^ u.second ^ v.second); } if (outer.is_valid) ans[j] = true; outer.is_valid = true; for(int t = i * BLOCK; t < queries[j].first; ++t){ pair<int,int> u = mst.find_set(edge[t].first), v = mst.find_set(edge[t].second); outer.parent[u.first] = make_pair(u.first, 0); outer.parent[v.first] = make_pair(v.first, 0); outer.sz[u.first] = outer.sz[v.first] = 1; } } } for(int i = 0; i< q; ++i) if (ans[i]) cout << "NO\n"; else cout << "YES\n"; } int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << " ms!\n"; 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...