Submission #579935

#TimeUsernameProblemLanguageResultExecution timeMemory
579935drdilyorXor Sort (eJOI20_xorsort)C++17
0 / 100
1 ms212 KiB
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS) #define _GLIBCXX_ASSERTIONS #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #ifdef ONPC #include "t_debug.cpp" #else #define debug(...) 42 #endif #define allit(a) (a).begin(), (a).end() #define sz(a) ((int) (a).size()) using namespace std; using ll = long long; using vi = vector<int>; namespace pd = __gnu_pbds; template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>; template<typename... T> using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings const int INF = 1e9; const ll INFL = 1e18; const int N = 1e5; const int K = 10; // 20 const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); int solve() { int n, s; cin >> n >> s; vi a(n); for (auto& i : a) cin >> i; vector<pair<int,int>> res; #define DO(i, j) {res.emplace_back(i, j); a[i] ^= a[j];} auto print = [&]() { for (int i = 0; i < n; i++) cerr << bitset<K>(a[i]) << ' '; cerr << endl; }; for (int b = K-1; b >= 0; b--) { //carry bit to the end int end = n-1; for (int i = 0; i < end; i++) { if (a[i] & (1<<b)) { if (! (a[i+1] & (1 << b))) DO(i+1, i); } } debug(a, end); } #ifdef ONPC debug(a); for (int i = 0; i < n-1; i++) { assert(s == 1 ? a[i] < a[i+1] : a[i] <= a[i+1]); } #endif //#ifndef ONPC cout << res.size() << '\n'; for (auto [i, j] : res) cout << i+1 << ' ' << j+1 << '\n'; //#endif return 0; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; #ifdef ONPC cin >> t; #endif while (t-- && cin) { if (solve()) break; #ifdef ONPC cout << "____________________" << endl; #endif } return 0; }

Compilation message (stderr)

xorsort.cpp: In function 'int solve()':
xorsort.cpp:10:24: warning: statement has no effect [-Wunused-value]
   10 |     #define debug(...) 42
      |                        ^~
xorsort.cpp:50:9: note: in expansion of macro 'debug'
   50 |         debug(a, end);
      |         ^~~~~
xorsort.cpp:36:10: warning: variable 'print' set but not used [-Wunused-but-set-variable]
   36 |     auto print = [&]() {
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...