Niloy007

1521_War_Games_2

Apr 10th, 2021
485
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Problem Link: https://acm.timus.ru/problem.aspx?space=1&num=1521
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #define Niloy
  8. #define int int64_t
  9. #define MAX 1000
  10. #define MOD 1e9
  11. #define pb push_back
  12. #define pairs pair<int, int>
  13. #define vi vector<int>
  14. #define vb vector<bool>
  15. #define vii vector<pairs>
  16. #define lb lower_bound
  17. #define ub upper_bound
  18. #define endl '\n'
  19. #define llu unsigned long long
  20. using namespace std;
  21. using namespace __gnu_pbds;
  22. // Policy Based Data Structure
  23. typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
  24. /* ----------------------------------------------------------------------------------- */
  25.  
  26. // Input/Output
  27. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  28. #define all(x) x.begin(), x.end()
  29. #define square(a) (a * a)
  30. #define mem(a, b) memset(a, b, sizeof(a))
  31.  
  32. // Fractional Number
  33. #define fraction()        cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
  34.  
  35. #define scan(a)           scanf("%lld", &a);
  36. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
  37. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
  38. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  39.  
  40. #define scanD(a)          scanf("%lf", &a);
  41. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
  42. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
  43. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
  44.  
  45.  
  46. #define print(a)           printf("%lld\n", a);
  47. #define print2(a, b)       printf("%lld %lld\n", a, b);
  48. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
  49. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
  50.  
  51. #define printD(a)          printf("%lf\n", a);
  52. #define printD2(a, b)      printf("%lf %lf\n", a, b);
  53. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
  54. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
  55. #define printTwoD(a)       printf("%.2lf\n", a);
  56.  
  57. // File I/O
  58. #define read(x)  freopen(x, "r", stdin);
  59. #define write(x) freopen(x, "w", stdout);
  60.  
  61. // Loops
  62. #define rep(i, a, n) for (int i = a; i < n; i++)
  63. #define REP(i, a, n) for (int i = a; i <= n; i++)
  64. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
  65. #define REV(i, n, a) for (int i = n; i >= a; i--)
  66. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  67. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  68. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  69.  
  70. /* ----------------------------------------------------------------------------------- */
  71.  
  72. #define Cases  cout << "Case " << ++Case << ": ";
  73. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  74. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  75.  
  76. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
  77. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  78. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  79.  
  80. /* ----------------------------------------------------------------------------------- */
  81.  
  82. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
  83. int lcm(int n, int m) { return n / gcd(n, m) * m; }
  84.  
  85. struct debugger {
  86.     typedef string::iterator si;
  87.     static void call(si it, si ed) {}
  88.     template<typename T, typename ... aT>
  89.     static void call(si it, si ed, T a, aT... rest) {
  90.         string b;
  91.         for(; *it!=','; ++it)
  92.             if(*it!=' ')
  93.                 b+=*it;
  94.         cout << b << "=" << a << " ";
  95.         call(++it, ed, rest...);
  96.     }
  97. };
  98.  
  99. /* ----------------------------------------------------------------------------------- */
  100.  
  101. /// change ll to any data type
  102. /// less_equal for multiset increasing order
  103. /// less for set increasing order
  104. /// greater_equal for multiset decreasing order
  105. /// greater for set decreasing order
  106.  
  107. /// cout<<*X.find_by_order(1)<<endl; // iterator to the k-th element
  108. /// cout<<X.order_of_key(-5)<<endl;  // number of items in a set that are strictly smaller than our item
  109.  
  110. /* ----------------------------------------------------------------------------------- */
  111. void input() {
  112. #ifdef Niloy
  113.     read("input.txt");  
  114.     write("output.txt");
  115. #endif
  116. }
  117.  
  118. /* ----------------------------------------------------------------------------------- */
  119.  
  120.  
  121. void solve() {
  122.     int n, k;
  123.     scan2(n, k);
  124.     ordered_set ps;
  125.     REP(i, 1, n) {
  126.         ps.insert(i);
  127.     }
  128.    
  129.     int p = 0;
  130.     while (ps.size() > 0) {
  131.         p += (k - 1);
  132.         p %= ps.size();
  133.         int value = *ps.find_by_order(p);
  134.         cout << value << " ";
  135.         ps.erase(value);
  136.         p = ps.order_of_key(value);
  137.     }
  138.  
  139.     cout << endl;
  140. }
  141.  
  142. int32_t main() {
  143.     // input();
  144.     // fastInput;
  145.     solve();
  146.  
  147.     // __test {
  148.     //  solve();
  149.     // }
  150.  
  151.     // showTime;
  152.     return 0;
  153. }
  154.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×