SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 20th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17. #include <unordered_set>
  18.  
  19.  
  20. //#pragma GCC optimize("Ofast,no-stack-protector")
  21. //#pragma GCC optimize("O3")
  22. //#pragma GCC target("avx2")
  23. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  24. //#pragma GCC optimize("unroll-loops")
  25. //#pragma GCC optimize("fast-math")
  26. //#pragma GCC optimize("section-anchors")
  27. //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  28. //#pragma GCC optimize("vpt")
  29. //#pragma GCC optimize("rename-registers")
  30. //#pragma GCC optimize("move-loop-invariants")
  31. //#pragma GCC optimize("unswitch-loops")
  32. //#pragma GCC optimize("function-sections")
  33. //#pragma GCC optimize("data-sections")
  34. //#pragma GCC optimize("branch-target-load-optimize")
  35. //#pragma GCC optimize("branch-target-load-optimize2")
  36. //#pragma GCC optimize("btr-bb-exclusive")
  37. //#pragma GCC optimize("O0")
  38.  
  39.  
  40. #define int long long
  41. #define ll long long
  42. #define ull unsigned long long
  43. #define all(a) a.begin(), a.end()
  44. #define pii pair<int, int>
  45. #define pb push_back
  46. #define ld long double
  47.  
  48.  
  49. using namespace std;
  50.  
  51. const int INF = 1e17;
  52. //const int mod = 2600000069;
  53. //const int p = 179;
  54.  
  55. int n, p;
  56. vector<int> a, t;
  57.  
  58. void build(int v, int l, int r) {
  59.     if (r - l == 1) {
  60.         t[v] = a[l];
  61.         return;
  62.     }
  63.     int m = (l + r) / 2;
  64.     build(2 * v + 1, l, m);
  65.     build(2 * v + 2, m, r);
  66.     t[v] = min(t[2 * v + 1], t[2 * v + 2]);
  67. }
  68.  
  69. void update(int v, int l, int r, int pos) {
  70.     if (r - l == 1) {t[v] = INF; return;}
  71.     int m = (l + r ) / 2;
  72.     if (pos < m) update(2 * v + 1, l, m, pos);
  73.     else update(2 * v + 2, m, r, pos);
  74.     t[v] = min(t[2  *v + 1], t[2 * v + 2]);
  75. }
  76.  
  77. int tim = INF;
  78.  
  79. int get_pos(int v, int l, int r) {
  80.     if (r - l == 1) {
  81.         return l;
  82.     }
  83.     int m = (l + r ) / 2;
  84.     if (t[2 *  v + 1] <= tim) return get_pos(2 * v + 1, l, m);
  85.     else return get_pos(2 * v + 2, m, r);
  86. }
  87.  
  88. signed main() {
  89.     ios_base::sync_with_stdio(0);
  90.     cin.tie(0);
  91.     cout.tie(0);
  92.     int n;
  93.     cin >> n >> p;
  94.     a.resize(n);
  95.     t.resize(4 * n);
  96.     for (int i = 0; i < n; i++) {cin >>a[i]; tim = min(tim, a[i]);}
  97.     build(0, 0, n);
  98.     int cur;
  99.     vector<int> ans(n);
  100.     while(t[0] != INF) {
  101.         cur = get_pos(0, 0, n);
  102.         ans[cur] = max(tim + p, a[cur] + p);
  103.         tim = ans[cur];
  104.         update(0, 0, n, cur);
  105.         tim = max(tim, t[0]);
  106.     }
  107.     for (auto k : ans) cout << k << " ";
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top