Advertisement
tiom4eg

day 1, D 100 (0.974 max)

Jan 9th, 2023
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O2") // let the chaos begin!
  29. //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. //#pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. #define ook order_of_key
  37. #define fbo find_by_order
  38. using namespace __gnu_pbds;
  39. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  40. using namespace std;
  41. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  42. //#define int long long
  43. const int INF = 1e9 + 7, MD = 998244353, MAX = 300005, R = 1 << 19, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, MOD12 = MOD1 * MOD1, MOD22 = MOD2 * MOD2, LG = 20, B1 = 103, B2 = 107, S = 10008;
  44. const ll INFLL = 1e18 + 7;
  45.  
  46. int nx[MAX][LG], lv[MAX][LG];
  47. vector <pii> cur, o[LG];
  48.  
  49. signed main() {
  50.     fastIO;
  51.     int n, m, k, b = 0, g = 0, r = 0; cin >> n >> m >> k, --k;
  52.     cur.reserve(n);
  53.     pair <int, char> t[n];
  54.     FOR(i, 0, n) {
  55.         cin >> t[i].F >> t[i].S, --t[i].F;
  56.         if (t[i].S == 'B') ++b;
  57.         else if (t[i].S == 'G') ++g;
  58.         else ++r;
  59.     }
  60.     FOR(i, 0, n) nx[i][0] = t[i].F;
  61.     FOR(i, 1, LG) FOR(j, 0, n) nx[j][i] = nx[nx[j][i - 1]][i - 1];
  62.     FOR(i, 0, n) {
  63.         if (t[i].S == 'B') lv[i][0] = 0;
  64.         else if (t[i].S == 'G') lv[i][0] = b;
  65.         else lv[i][0] = b + g;
  66.         o[0].pb({lv[i][0], i});
  67.     }
  68.     sort(all(o[0]));
  69.     FOR(i, 1, LG) {
  70.         int p = 0;
  71.         FOR(j, 1, n) if (o[i - 1][p].F < o[i - 1][j].F) {
  72.             FOR(k, p, j) cur.pb({lv[nx[o[i - 1][k].S][i - 1]][i - 1], o[i - 1][k].S});
  73.             sort(all(cur));
  74.             lv[cur[0].S][i] = p, o[i].pb({p, cur[0].S});
  75.             FOR(k, 1, j - p) lv[cur[k].S][i] = (cur[k].F == cur[k - 1].F ? lv[cur[k - 1].S][i] : p + k), o[i].pb({lv[cur[k].S][i], cur[k].S});
  76.             cur.clear(), p = j;
  77.         }
  78.         vector <pii> cur;
  79.         FOR(k, p, n) cur.pb({lv[nx[o[i - 1][k].S][i - 1]][i - 1], o[i - 1][k].S});
  80.         sort(all(cur));
  81.         lv[cur[0].S][i] = p, o[i].pb({p, cur[0].S});
  82.         FOR(k, 1, n - p) lv[cur[k].S][i] = (cur[k].F == cur[k - 1].F ? lv[cur[k - 1].S][i] : p + k), o[i].pb({lv[cur[k].S][i], cur[k].S});
  83.         cur.clear();
  84.     }
  85.     int st = o[LG - 1][n - 1].S;
  86.     FOR(i, 0, n) if (o[LG - 1][i].F > k) {
  87.         st = o[LG - 1][i - 1].S;
  88.         break;
  89.     }
  90.     FOR(i, 0, m) {
  91.         cout << t[st].S;
  92.         st = t[st].F;
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement