This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int>> pq;
int ans[500001];
void solve(int n, int m) {
if (n == 1) ans[0] = m;
if (n <= 1) return;
int t = -1;
for (int i = 1; i < 21; i++) {
int a = (1 << i) - 1;
if (a < n) t = a;
}
int k = -1;
for (int i = m; i < m + n; i++) {
if ((t & i) == t) {
k = i;
break;
}
}
// t와 k의 싱크가 일치.
// t~n과 k~k+(n-t)의 짝을 지어줌.
// 0~1, 3~4니까.
// 1이 3이랑 매칭되고.
//
for (int i = t; i < n; i++) ans[i] = k + (i - t);
for (int i = k - 1; i >= m; i--) ans[t - (k - i)] = i;
solve(t - (k - m), k + (n - t));
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
solve(n, m);
for (int i = 0; i < n; i++)
printf("%d %d\n" , i, ans[i]);
}
Compilation message (stderr)
sob.cpp: In function 'int main()':
sob.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |