Submission #218639

#TimeUsernameProblemLanguageResultExecution timeMemory
218639VimmerMatching (COCI20_matching)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define N 100005 #define M ll(998244353) using namespace std; //using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef short int si; //typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set; int x[N], y[N], a[N][2], n, xr[N], yr[N]; set <int> tx[N * 4], ty[N * 4]; vector <int> pshx[N * 4], pshy[N * 4]; bool mk[N]; queue <pair <int, int> > qr; queue <int> alone; vector <pair <int, int> > vert, gorz; void Push(int v, int tl, int tr) { while (sz(pshx[v]) > 0) { int val = pshx[v].back(); pshx[v].pop_back(); tx[v].insert(val); if (tl != tr) {pshx[v + v].pb(val); pshx[v + v + 1].pb(val);} } while (sz(pshy[v]) > 0) { int val = pshy[v].back(); pshy[v].pop_back(); ty[v].insert(val); if (tl != tr) {pshy[v + v].pb(val); pshy[v + v + 1].pb(val);} } } void upd(int v, int tl, int tr, int l, int r, int val, bool f) { Push(v, tl, tr); if (tl > tr || l > r || r < tl || tr < l) return; if (l <= tl && tr <= r) {if (!f) pshx[v].pb(val); else pshy[v].pb(val); Push(v, tl, tr); return;} int md = (tl + tr) >> 1; upd(v + v, tl, md, l, r, val, f); upd(v + v + 1, md + 1, tr, l, r, val, f); } bool good(int v, int tl, int tr, int pos, int l, int r, bool f) { Push(v, tl, tr); if (tl == tr) { set <int> :: iterator it; if (f) { it = ty[v].lower_bound(l); return (it == ty[v].end() ? 1 : *it > r); } else { it = tx[v].lower_bound(l); return (it == tx[v].end() ? 1 : *it > r); } } else { int md = (tl + tr) >> 1; if (pos <= md) return good(v + v, tl, md, pos, l, r, f); return good(v + v + 1, md + 1, tr, pos, l, r, f); } } bool gd(int fr, int sc) { if (x[fr] == x[sc]) { if (y[fr] > y[sc]) swap(fr, sc); return good(1, 1, N - 1, x[fr], y[fr], y[sc], 0); } else { if (x[fr] > x[sc]) swap(fr, sc); return good(1, 1, N - 1, y[fr], x[fr], x[sc], 1); } } void add(int fr, int sc) { if (x[fr] == x[sc]) { gorz.pb({fr, sc}); if (y[fr] > y[sc]) swap(fr, sc); upd(1, 1, N - 1, y[fr], y[sc], x[fr], 1); } else { vert.pb({fr, sc}); if (x[fr] > x[sc]) swap(fr, sc); upd(1, 1, N - 1, x[fr], x[sc], y[fr], 0); } } void clr(int x) { mk[x] = 1; if (a[x][1] != -1) {if (!mk[a[x][1]]) alone.push(a[x][1]); a[x][1] = a[a[x][1]][1] = -1;} if (a[x][0] != -1) {if (!mk[a[x][0]]) alone.push(a[x][0]); a[x][0] = a[a[x][0]][0] = -1;} } void fnd() { while (sz(alone) > 0) { int v = alone.front(); alone.pop(); if (a[i][1] != -1 && gd(i, a[i][1])) {qr.push({a[i][1], i}); a[i][1] = a[a[i][1]][1] = -1; return;} if (a[i][0] != -1 && gd(i, a[i][0])) {qr.push({a[i][0], i}); a[i][0] = a[a[i][0]][0] = -1; return;} cout << "NE" << endl; exit(0); } for (int i = 0; i < n; i++) { if (mk[i]) continue; if (a[i][1] == -1 && a[i][0] == -1) continue; bool f0 = gd(i, a[i][0]); bool f1 = gd(i, a[i][1]); if (f0 && f1) continue; if (!f0 && !f1) continue; if (f0) { qr.push({i, a[i][0]}); a[i][0] = a[a[i][0]][0] = -1; return; } else { qr.push({i, a[i][1]}); a[i][1] = a[a[i][1]][1] = -1; return; } } for (int i = 0; i < n; i++) { if (mk[i]) continue; if (a[i][1] == -1 && a[i][0] == -1) continue; if (!gd(i, a[i][0]) && !gd(i, a[i][1])) continue; if (!gd(i, a[i][0])) { qr.push({i, a[i][1]}); a[i][1] = a[a[i][1]][1] = -1; return; } else { qr.push({i, a[i][0]}); a[i][0] = a[a[i][0]][0] = -1; return; } } } int main() { ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i < N; i++) xr[i] = yr[i] = -1; for (int i = 0; i < n; i++) {cin >> x[i] >> y[i]; a[i][0] = a[i][1] = -1;} for (int i = 0; i < n; i++) { int X = x[i], Y = y[i]; if (xr[X] == -1) xr[X] = i; else {a[i][0] = xr[X]; a[xr[X]][0] = i;} if (yr[Y] == -1) yr[Y] = i; else {a[i][1] = yr[Y]; a[yr[Y]][1] = i;} } for (int i = 0; i < n; i++) if (a[i][0] == a[i][1] && a[i][1] == -1) {cout << "NE" << endl; exit(0);} for (int i = 0; i < n; i++) if (a[i][0] == -1 || a[i][1] == -1) alone.push(i); fnd(); while (sz(qr) > 0) { int fr = qr.front().F; int sc = qr.front().S; qr.pop(); if (gd(fr, sc)) { mk[sc] = 1; clr(fr); clr(sc); add(fr, sc); } fnd(); } if (sz(vert) + sz(gorz) != n / 2) {cout << "NE" << endl; exit(0);} cout << "DA" << endl; for (auto it : gorz) cout << it.F + 1 << " " << it.S + 1 << endl; for (auto it : vert) cout << it.F + 1 << " " << it.S + 1 << endl; }

Compilation message (stderr)

matching.cpp: In function 'void fnd()':
matching.cpp:159:15: error: 'i' was not declared in this scope
         if (a[i][1] != -1 && gd(i, a[i][1])) {qr.push({a[i][1], i}); a[i][1] = a[a[i][1]][1] = -1; return;}
               ^
matching.cpp:159:67: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
         if (a[i][1] != -1 && gd(i, a[i][1])) {qr.push({a[i][1], i}); a[i][1] = a[a[i][1]][1] = -1; return;}
                                                                   ^
In file included from /usr/include/c++/7/queue:64:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from matching.cpp:1:
/usr/include/c++/7/bits/stl_queue.h:251:7: note: candidate: void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]
       push(const value_type& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:251:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_queue.h:256:7: note: candidate: void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]
       push(value_type&& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:256:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
matching.cpp:161:15: error: 'i' was not declared in this scope
         if (a[i][0] != -1 && gd(i, a[i][0])) {qr.push({a[i][0], i}); a[i][0] = a[a[i][0]][0] = -1; return;}
               ^
matching.cpp:161:67: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
         if (a[i][0] != -1 && gd(i, a[i][0])) {qr.push({a[i][0], i}); a[i][0] = a[a[i][0]][0] = -1; return;}
                                                                   ^
In file included from /usr/include/c++/7/queue:64:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from matching.cpp:1:
/usr/include/c++/7/bits/stl_queue.h:251:7: note: candidate: void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]
       push(const value_type& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:251:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_queue.h:256:7: note: candidate: void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]
       push(value_type&& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:256:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
matching.cpp:155:13: warning: unused variable 'v' [-Wunused-variable]
         int v = alone.front();
             ^