Submission #375066

#TimeUsernameProblemLanguageResultExecution timeMemory
375066Kevin_Zhang_TWMeetings (JOI19_meetings)C++17
100 / 100
911 ms1260 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; using ll = long long; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 300010; // function : Query(a, b, c) // function : Bridge(a, b) random_device rd; //mt19937 gen(rd()); mt19937 gen; #define qry Query vector<pair<int,int>> res; void solve(vector<int> ids) { if (ids.size() <= 1) return; if (ids.size() == 2) { res.pb(ids[0], ids[1]); return; } shuffle(AI(ids), gen); int a = ids[0], b = ids[1]; map<int, vector<int>> subtree; vector<int> sorted; for (int i = 2;i < ids.size();++i) { int x = ids[i], anc = qry(a, b, x); subtree[anc].pb(x); if (anc != a && anc != b) sorted.pb(anc); } subtree[a].pb(a), subtree[b].pb(b); for (auto [_, sid] : subtree) solve(sid); sort(AI(sorted)); sorted.erase(unique(AI(sorted)), end(sorted)); int root = a; set<pair<int,int>> vis; auto cmp = [&](int a, int b) { if (vis.count({a, b})) return true; if (vis.count({b, a})) return false; int mid = qry(root, a, b); vis.insert({mid, a + b - mid}); return mid == a; }; stable_sort(AI(sorted), cmp); int lst = root; for (int u : sorted) { res.pb(lst, u), lst = u; } res.pb(lst, b); } void Solve(int N) { static int cnt; assert(++cnt == 1); vector<int> ids(N); iota(AI(ids), 0); solve(ids); assert(res.size() == N-1); for (auto &[a, b] : res) { if (a > b) swap(a, b); DE(a, b); Bridge(a, b); } }

Compilation message (stderr)

meetings.cpp: In function 'void solve(std::vector<int>)':
meetings.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 2;i < ids.size();++i) {
      |                 ~~^~~~~~~~~~~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from meetings.cpp:2:
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:85:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |  assert(res.size() == N-1);
      |         ~~~~~~~~~~~^~~~~~
meetings.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
meetings.cpp:88:3: note: in expansion of macro 'DE'
   88 |   DE(a, b);
      |   ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...