# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
202651 | SorahISA | Sob (COCI19_sob) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int maxn = 1 << 20;
vector<int> v(maxn);
int32_t main() {
fastIO();
int n, m;
cin >> n >> m;
/// for subtask 1 : n == 2^k ///
if ((1 << __lg(n)) == n) {
for (int i = m+n-1; i >= m; --i) {
if (((n-1) & i) == (n-1)) {tok = i+1-n; break;}
}
for (int i = 0; i < n; ++i) {
cout << i << " " << (tok+i < m ? tok+i+n : tok+i) << "\n";
}
return 0;
}
/// for subtask 2 : n+m == 2^k ///
int now = 1, p;
for (int i = 1; i < n; ++i) {
now = (now ? now - 1 : i - 1);
p = now;
while (v[now]) {
swap(v[now], v[p]);
p += (1 << (int)__lg(v[now]) + 1);
}
v[now] = i;
}
vector<pair<int, int>> ans;
for (int i = 0; i < n; ++i) ans.push_back({v[i], n+m-i-1});
sort(ans.begin(), ans.end());
for (auto [L, R] : ans) cout << L << " " << R << "\n";
return 0;
}