Codeforces Round 934 (Div. 2)
B. Equal XOR
测试案例解释有误导性,异或运算,相同数字异或为0,每个数字都出现两次,不是两个都在一边,就是一边一个,只需要分开来输出即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--) { int n,k; cin >> n >> k; int a[2*n]; vector<int> pos[n+1]; for(int i=0;i<2*n;++i) { cin >> a[i]; pos[a[i]].push_back(i); } vector<int> l,r;
for(int i=1;i<=n;++i) { if(pos[i].front() < n && pos[i].back() <n && l.size()<2*k) { l.push_back(i); l.push_back(i); } else if(pos[i].front()>=n && pos[i].back() >=n &&r.size()<2*k) { r.push_back(i); r.push_back(i); } } for(int i=1;i<=n;++i) { if((pos[i].front()<n&&pos[i].back()<n) || (pos[i].front()>=n&&pos[i].back()>=n)) { continue; } if(l.size()<2*k) { l.push_back(i); r.push_back(i); } } for(auto i : l) cout << i << " "; cout << endl; for(auto i : r) cout << i << " "; cout << endl; } }
|