Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- //#define ull unsigned long long
- #define pii pair <int, int>
- #define vi vector <int>
- #define mi vector <vector <int>>
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)(a.size())
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- #define EACH(e, a) for (auto& e : a)
- // Pragmas
- #ifndef TIOM4EG
- #pragma GCC optimize("O3") // let the chaos begin!
- #pragma GCC target("avx,avx2,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- #endif
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define pbds tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- using namespace __gnu_pbds;
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
- //#define int long long
- constexpr int INF = 1e9 + 7, MD = 998244353, MAX = 100007, LG = 19, R = 1 << LG, MOD = 1000000007, MOD2 = 1e9 + 9, B = 256;
- const ll INFLL = 1e18 + 7;
- #undef endl
- int group;
- struct opi {
- int f, s;
- opi() {}
- opi(int x, int y) : f(min(x, y)), s(max(x, y)) {}
- bool operator<(const opi o) const { return (f == o.f) ? (s < o.s) : (f < o.f); }
- bool operator==(const opi o) const { return f == o.f && s == o.s; }
- };
- template<>
- struct std::hash <opi> {
- int operator() (opi p) const { return p.f << 16 + p.s; }
- };
- /*
- global ideas:
- good vertex: vertex which doesn't have two found outgoing edges
- bad vertex: vertex which has 2+ outgoing edges
- first-priority edge: non-asked edge between two good vertices
- second-priority edge: non-asked edge which isn't first-priority
- */
- /*
- idea: try every first-priority edge while they exist, their number is <= 2n
- after that (it can be proven) we're left with no more than 3 good vertices
- bruteforce them in 3n
- */
- void solve_5n() {
- int n; cin >> n;
- vi cnt(n);
- unordered_set <opi> kal;
- function <int(opi)> ask = [](opi e) {
- cout << "? " << e.f + 1 << ' ' << e.s + 1 << endl;
- string r; cin >> r;
- return r[0] != 'f';
- };
- FOR(i, 0, n) {
- FOR(j, i + 1, n) {
- if (cnt[i] > 1) break;
- if (cnt[j] > 1) continue;
- opi cur(i, j);
- kal.insert(cur);
- int d = ask(cur);
- ++cnt[d ? cur.s : cur.f];
- }
- }
- FOR(v, 0, n) if (cnt[v] < 2) {
- bool ok = 1;
- FOR(u, 0, n) if (u != v && kal.find({u, v}) == kal.end()) {
- opi cur(v, u);
- kal.insert(cur);
- int d = ask(cur);
- if (v == (d ? cur.s : cur.f)) {
- if (++cnt[v] == 2) {
- ok = 0;
- break;
- }
- }
- }
- if (ok) {
- cout << "! " << v + 1 << endl;
- string verdict; cin >> verdict;
- return;
- }
- }
- cout << "! -1" << endl;
- string verdict; cin >> verdict;
- }
- void solve_kukarek() {
- int n; cin >> n;
- bitset <250000> used;
- vi cnt(n);
- set <pii> q;
- FOR(i, 0, n) q.insert({cnt[i], i});
- function <int(opi)> ask = [](opi e) {
- cout << "? " << e.f + 1 << ' ' << e.s + 1 << endl;
- string r; cin >> r;
- return r[0] != 'f';
- };
- FOR(iter, 0, 2000) {
- pii cur = *q.begin(), now;
- if (cur.F > 1) break;
- q.erase(q.begin());
- bool found = 0;
- for (auto it = q.begin(); it != q.end(); ++it) {
- if (!used[cur.S * n + it->S]) {
- now = *it;
- cout << "? " << cur.S + 1 << ' ' << now.S + 1 << endl;
- string r; cin >> r;
- int d = r[0] != 'f';
- if (d) {
- q.erase(it);
- cnt[now.S]++;
- q.insert({cnt[now.S], now.S});
- }
- else ++cnt[cur.S];
- q.insert({cnt[cur.S], cur.S});
- used[cur.S * n + now.S] = used[now.S * n + cur.S] = 1;
- found = 1;
- break;
- }
- }
- if (!found) {
- cout << "! " << cur.S + 1 << endl;
- string verdict; cin >> verdict;
- return;
- }
- }
- cout << "! -1" << endl;
- string verdict; cin >> verdict;
- }
- signed main() {
- fastIO;
- int tc; cin >> group >> tc;
- while (tc--) solve_kukarek();
- }
Advertisement
Add Comment
Please, Sign In to add comment