# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516054 | 2022-01-20T10:44:14 Z | lovrot | Minerals (JOI19_minerals) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include <"materials.h"> #define vec vector #define siz size() #define pri(i, poc, n, pov) for(int i = (int) poc; i < (int) n; i += (int) pov) #define pb push_back #define X first #define Y second using namespace std; const int N = 43010; //bool on[N]; //int query_ans; int qans; vec<pair<int, int>> ans; map<int, int> ans_esp; /* int Query(int x){ int y = ans_esp[x]; if(!on[x]){ if(!on[y]) query_ans++; on[x] = 1; } else{ if(!on[y]) query_ans--; on[x] = 0; } //cout << "on query " << x << " " << query_ans << " " << query_ans - qans << "\n"; return query_ans; }*/ void divcon(vec<int> &a, vec<int> &b){ if(a.siz == 1){ //ans.pb({a[0], b[0]}); Answer(a[0], b[0]); return; } if(!a.siz){ return; } vec<int> a_left; vec<int> b_left; vec<int> a_rght; vec<int> b_rght; int h = a.siz / 2; int raz, newans, pom; pri(i, 0, a.siz, 1){ if(i < h){ newans = Query(a[i]); raz = newans - qans; qans = newans; a_left.pb(a[i]); } else a_rght.pb(a[i]); } /*if(raz != 0 && raz != 1) cout << "f\n"; */ pri(i, 0, a.siz, 1){ newans = Query(b[i]); pom = newans - qans; if((raz == 0 && pom == -1) || (raz == 1 && pom == 0)) b_left.pb(b[i]); else{ newans = Query(b[i]); b_rght.pb(b[i]); } qans = newans; } /* for(int i : a) cout << i << " "; cout << "\n"; for(int i : b) cout << i << " "; cout << "\n"; for(int i : a_left) cout << i << " "; cout << "\n"; for(int i : b_left) cout << i << " "; cout << "\n\n"; for(int i : a_rght) cout << i << " "; cout << "\n"; for(int i : b_rght) cout << i << " "; cout << "\n---------------\n"; */ divcon(a_left, b_left); divcon(a_rght, b_rght); } void Solve(int n){ vec<int> a; vec<int> b; int newans; pri(i, 1, n * 2 + 1, 1){ newans = Query(i); if(newans - qans){ a.pb(i); } else{ b.pb(i); } qans = newans; } divcon(a, b); } /* int main(){ ios_base::sync_with_stdio(0); int n; cin >> n; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; ans_esp[x] = y; ans_esp[y] = x; } Solve(n); for(int i = 0; i < n; i++){ int x = ans[i].X; int y = ans[i].Y; if(ans_esp[x] != y && ans_esp[y] != x){ cout << "Invalid\n"; exit(0); } } cout << "Correct\n"; return 0; } */