Advertisement
Galebickosikasa

Untitled

Sep 1st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. #define int ll
  36.  
  37. using namespace std;
  38.  
  39. #ifdef __LOCAL
  40. #define dbg(x) cerr << #x << " : " << x << '\n'
  41. const int maxn = 20;
  42. #else
  43. #define dbg(x)
  44. const int maxn = 2e5 + 20;
  45. #endif
  46.  
  47. //tg: @galebickosikasa
  48.  
  49. ostream& operator << (ostream& out, vector<int>& v) {
  50. for (auto& x: v) out << x << ' ';
  51. return out;
  52. }
  53.  
  54. ostream& operator << (ostream& out, pii& v) {
  55. out << v.fi << ", " << v.se;
  56. return out;
  57. }
  58.  
  59. istream& operator >> (istream& in, pii& a) {
  60. in >> a.fi >> a.se;
  61. return in;
  62. }
  63.  
  64. const ll inf = (ll) 2e9;
  65. const ld pi = asin (1) * 2;
  66. const ld eps = 1e-8;
  67. const ll mod = (ll)1e9 + 7;
  68. const ll ns = 97;
  69.  
  70. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  71.  
  72.  
  73.  
  74. signed main () {
  75. ios_base::sync_with_stdio(false);
  76. cin.tie(nullptr);
  77. cout.tie(nullptr);
  78. int n, q, k;
  79. cin >> n >> q >> k;
  80. vector<pii> moo (q);
  81. cinv (moo);
  82. vector<int> goo (n);
  83. cinv (goo);
  84. fr (j, 2) fr (i, n) goo.pb (goo[i]);
  85. reverse (all (moo));
  86. for (auto& x: moo) x.se *= -1;
  87. int block = 0, ost = 0;
  88. for (auto& t: moo) {
  89. if (t.fi == 1) {
  90. int x = t.se;
  91. x = abs (x);
  92. x %= k;
  93. if (t.se >= 0) ost += x;
  94. else ost -= x;
  95. if (ost >= k) ost -= k;
  96. if (ost < 0) ost += k;
  97. } else {
  98. int x = t.se;
  99. x = abs (x);
  100. int c = x / k;
  101. c %= n;
  102. if (t.se > 0) block += c;
  103. else block -= c;
  104. x %= k;
  105. if (t.se > 0) ost += x;
  106. else ost -= x;
  107. if (ost >= k) {
  108. ost -= k;
  109. ++block;
  110. }
  111. if (ost < 0) {
  112. ost += k;
  113. --block;
  114. }
  115. if (block >= n / k) block -= n / k;
  116. if (block < 0) block += n / k;
  117. }
  118. dbg (block);
  119. dbg (ost);
  120. }
  121. vector<vector<int>> ans (n / k);
  122. int st = n - ost, end = n - ost + k;
  123. fr (j, n / k) {
  124. fl (i, st, end) {
  125. ans[j].pb (goo[i]);
  126. }
  127. st = end, end += k;
  128. }
  129. int x = n / k - block;
  130. fl (i, x, sz (ans)) cout << ans[i];
  131. fr (i, x) cout << ans[i];
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement