Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 1e3+10;
- int a[maxn], n, s;
- void fast_io() {
- ios_base :: sync_with_stdio(0);
- cin.tie(nullptr);
- cout.tie(nullptr);
- }
- void read() {
- cin >> n >> s;
- for (int i = 1 ; i <= n ; ++i)
- cin >> a[i];
- }
- vector < pair < int, int > > v;
- void operation(int x, int y) {
- if (x < 1 || x > n || y < 1 || y > n) return;
- v.push_back({x, y});
- a[x] ^= a[y];
- }
- void solve() {
- int beg = 0;
- for (int log = 19 ; log >= 0 ; --log) {
- for (int i = 1 ; i <= n-beg ; ++i) {
- if (a[i] & (1 << log)) {
- if (i < n && (!(a[i+1] & (1 << log)))) operation(i+1, i);
- if (a[i-1] & (1 << log)) operation(i-1, i);
- }
- }
- beg += ((a[n-beg] & (1 << log)) > 0);
- }
- cout << v.size() << '\n';
- for (auto [x, y] : v)
- cout << x << ' ' << y << '\n';
- }
- void solve25() {
- int last_max = 0, max_ix;
- for (int iteration = 0 ; iteration < n-1 ; ++iteration) {
- max_ix = 1;
- for (int i = 2 ; i <= n-iteration ; ++i) {
- if ((a[i] ^ last_max) > (a[max_ix] ^ last_max)) max_ix = i;
- }
- for (int i = 1 ; i <= n-iteration - (iteration == 0) ; ++i) {
- operation(i, i+1);
- }
- for (int i = max_ix+1 ; i <= n-iteration ; ++i)
- operation(i, i-1);
- for (int i = max_ix-2 ; i >= 1 ; --i)
- operation(i, i+1);
- last_max = a[n-iteration];
- }
- operation(1, 2);
- // cout << "a: ";
- // for (int i = 1 ; i <= n ; ++i)
- // cout << a[i] << ' ';
- // cout << '\n';
- // return;
- cout << v.size() << '\n';
- for (auto [x, y] : v)
- cout << x << ' ' << y << '\n';
- }
- signed main () {
- fast_io();
- read();
- if (s == 1) solve25();
- else solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement