이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
bool has(int x, int bit) {
return (x >> bit) & 1;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n,s; cin >> n >> s;
int a[n]; for (int i = 0; i < n; cin >> a[i++]);
vector<pair<int,int>> oper;
auto operate = [&](int i, int j) {
a[i] ^= a[j];
oper.emplace_back(i+1, j+1);
};
if (s == 1) {
for (int iter = 0; iter < n-1; iter++) {
for (int i = 0; i < n-1; i++) {
if (a[i] > a[i+1]) {
operate(i, i+1);
operate(i+1, i);
operate(i, i+1);
}
}
}
} else {
for (int b = 20; b >= 0; b--) {
for (int i = 0; i < n-1; i++) {
if (a[i+1] >= (1 << b+1)) break;
if (has(a[i], b) && !has(a[i+1], b)) {
operate(i+1, i);
}
if (has(a[i], b) && has(a[i+1], b)) {
operate(i, i+1);
}
}
}
}
cout << oper.size() << "\n";
for (auto [i, j] : oper) cout << i << " " << j << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
xorsort.cpp: In function 'int main()':
xorsort.cpp:38:38: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
38 | if (a[i+1] >= (1 << b+1)) break;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |