288172026-05-31 11:35:06LazurAndrasXOR rendezéscpp17Elfogadva 100/1008ms1280 KiB
#include <bits/stdc++.h>
using namespace std;

void solve1(int n, vector<int>&a)
{
    vector<pair<int, int>>ans;
    vector<pair<int, int>>b(n);
    vector<int>pos(n);
    for(int i = 0; i < n; i++) b[i] = {a[i], i};
    sort(b.rbegin(), b.rend());
    for(int i = 0; i < n; i++)
    {
        int cnt = 0;
        for(int j = 0; j < i; j++) if(b[j].second < b[i].second) cnt++;
        pos[i] = b[i].second - cnt;
    }
    for(int i = 0; i < n; i++)
    {
        int last = n-i-1;
        int k = pos[i];
        for(int j = 0; j < last; j++)
        {
            a[j] ^= a[j+1];
            ans.push_back({j+1, j+2});
        }
        for(int j = k-2; j >= 0; j--)
        {
            a[j] ^= a[j+1];
            ans.push_back({j+1, j+2});
        }
        for(int j = k+1; j <= last; j++)
        {
            a[j] ^= a[j-1];
            ans.push_back({j+1, j});
        }
    }
    for(int i = n-2; i >= 0; i--)
    {
        a[i] ^= a[i+1];
        ans.push_back({i+1, i+2});
    }
    cout << (int)ans.size() << '\n';
    for(auto [l, r] : ans) cout << l << " " << r << '\n';
}

void solve2(int n, vector<int>&a)
{
    vector<pair<int, int>>ans;
    int cnt = n;
    for(int k = 19; k >= 0; k--)
    {
        bool ok = 0;
        for(int u : a) if((u >> k) & 1) ok = 1;
        if(!ok) continue;
        cnt--;
        for(int i = 0; i < cnt; i++)
        {
            if((a[i] >> k) & 1)
            {
                if((a[i+1] >> k) & 1)
                {
                    a[i] ^= a[i+1];
                    ans.push_back({i+1, i+2});
                }
                else
                {
                    a[i+1] ^= a[i];
                    a[i] ^= a[i+1];
                    ans.push_back({i+2, i+1});
                    ans.push_back({i+1, i+2});
                }
            }
        }
    }
    cout << (int)ans.size() << '\n';
    for(auto [l, r] : ans) cout << l << " " << r << '\n';
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
	int n, s; cin >> n >> s;
    vector<int>a(n);
    for(int &i : a) cin >> i;
    if(s == 1) solve1(n, a);
    else solve2(n, a);
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask125/25
1Elfogadva1ms316 KiB
2Elfogadva1ms512 KiB
3Elfogadva1ms316 KiB
4Elfogadva4ms692 KiB
5Elfogadva4ms1068 KiB
6Elfogadva4ms1012 KiB
7Elfogadva4ms692 KiB
8Elfogadva4ms824 KiB
9Elfogadva4ms1012 KiB
10Elfogadva4ms820 KiB
11Elfogadva4ms696 KiB
12Elfogadva4ms696 KiB
13Elfogadva6ms880 KiB
14Elfogadva6ms692 KiB
15Elfogadva6ms696 KiB
subtask235/35
1Elfogadva2ms508 KiB
2Elfogadva6ms820 KiB
3Elfogadva8ms948 KiB
4Elfogadva8ms948 KiB
5Elfogadva8ms1028 KiB
6Elfogadva8ms948 KiB
7Elfogadva8ms1024 KiB
8Elfogadva7ms1012 KiB
9Elfogadva8ms948 KiB
10Elfogadva8ms1132 KiB
11Elfogadva8ms1280 KiB
12Elfogadva8ms948 KiB
13Elfogadva8ms948 KiB
14Elfogadva8ms1144 KiB
15Elfogadva8ms992 KiB
subtask340/40
1Elfogadva2ms512 KiB
2Elfogadva1ms380 KiB
3Elfogadva1ms508 KiB
4Elfogadva2ms564 KiB
5Elfogadva7ms948 KiB
6Elfogadva6ms948 KiB
7Elfogadva6ms948 KiB
8Elfogadva6ms948 KiB
9Elfogadva8ms1012 KiB
10Elfogadva8ms948 KiB
11Elfogadva8ms1048 KiB
12Elfogadva8ms956 KiB
13Elfogadva7ms948 KiB
14Elfogadva7ms948 KiB
15Elfogadva8ms1124 KiB