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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #include <bits/stdc++.h> using namespace std;
#define int long long #define pii pair<int, int> #define F first #define S second #define vc vector #define vi vector<int> #define vii vector<pii> #define mii map<int, int> #define si set<int>
#define rep(i, a, b) for (int i = a; i <= b; ++i) #define rev(i, a, b) for (int i = a; i >= b; --i) #define tomax(a, b) (a) = max((a), (b)) #define tomin(a, b) (a) = min((a), (b)) #define all(a) a.begin(), a.end() #define rall(a) (a).rbegin(), (a).rend() #define pob pop_back #define pb push_back #define eb emplace_back #define sp << " " << #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define lc idx * 2 + 1 #define rc idx * 2 + 2
int seg[1000006]; int n, k;
void build(int idx, int l, int r) { if (r == l + 1) seg[idx] = 1; else { int mid = (r + l) / 2; build(lc, l, mid), build(rc, mid, r); seg[idx] = seg[lc] + seg[rc]; } }
void del(int idx, int l, int r, int pos) { seg[idx]--; int mid = (r + l) / 2; if (r == l + 1) return; else if (pos >= mid) del(rc, mid, r, pos); else del(lc, l, mid, pos); }
int query(int idx, int l, int r, int sum){ int mid = (l+r)/2; if(r==l+1) return l+sum; else if(sum>seg[lc]) return query(rc, mid, r, sum-seg[lc]); else return query(lc, l, mid, sum); }
signed main() { ios; cin >> n >> k; k++; build(0, 0, n); int idx = 0; rev(i, n, 1){ idx = (idx+(k%i))%i; if(idx == 0) idx = i; int pos = query(0, 0, n, idx); cout << pos << " "; del(0, 0, n, pos-1); idx--; } return 0; }
|