Salvens

Untitled

Jul 20th, 2023
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  7.  
  8. const long long INF = 1e18 + 7;
  9. const double EPS = 1e-6;
  10. const int MOD = 1e9 + 7;
  11. const int N = 1e3 + 10;
  12. const int K = 64;
  13. const int B = 500;
  14.  
  15. inline void solve() {
  16.     int n;
  17.     cin >> n;
  18.     vector<int> a(n);
  19.     for (int i = 0; i < n; ++i) {
  20.         cin >> a[i];
  21.     }
  22.     set<pair<int, int>> st;
  23.     map<int, int> used, min_color;
  24.     vector<int> ans(n);
  25.     st.insert({a[0], 1});
  26.     ans[0] = 1;
  27.     used[1] = a[0];
  28.     min_color[a[0]] = 1;
  29.     int max_color = 1;
  30.     for (int i = 1; i < n; ++i) {
  31.         auto it = st.lower_bound({a[i], 0});
  32.         if (it == st.end()) {
  33.             st.erase({used[1], 1});
  34.             st.insert({a[i], 1});
  35.             ans[i] = 1;
  36.             min_color[a[i]] = 1;
  37.             continue;
  38.         }
  39.         while (it != st.begin() && it->first >= a[i] && it->second > (--it)->second) {
  40.             --it;
  41.         }
  42.         if (it->first >= a[i]) {
  43.             st.insert({a[i], ++max_color});
  44.             ans[i] = max_color;
  45.             min_color[a[i]] = 1;
  46.         } else {
  47.             int x = it->first;
  48.             int col = it->second;
  49.             cout << x << ' ' << col << endl;
  50.             st.erase(it);
  51.             st.insert({a[i], col});
  52.             ans[i] = col;
  53.         }
  54.     }
  55.     cout << max_color << '\n';
  56.     for (auto i: ans) {
  57.         cout << i << ' ';
  58.     }
  59.     cout << '\n';
  60. }
  61.  
  62.  
  63. int32_t main() {
  64.     IOS;
  65.  
  66. //    freopen("palindrome.in", "r", stdin);
  67. //    freopen("palindrome.out", "w", stdout);
  68.  
  69.     cout << setprecision(10) << fixed;
  70.     int tt = 1;
  71. //    cin >> tt;
  72.     while (tt--) {
  73.         solve();
  74.     }
  75.     return 0;
  76. }
  77.  
  78. /*
  79. 1.  数组开够了没
  80. 2.  文件名写对了没,文件夹建了吗
  81. 3.  内存会不会MLE
  82. 4.  多测清空?
  83. 5.  调试删干净了没
  84. 6.  取模有没有溢出
  85. 7.  快速幂底数要取模,幂对 mod-1 取模
  86. 8.  前向星和欧拉序要开2倍数组
  87. 9.  比较函数如果值相同的话有没有第二优先级
  88. 10. 线段树 4 倍空间,线段树合并和可持久化线段树 32 倍空间
  89. 11. 看清楚 log 的底数是啥,log后面的数是啥
  90. 12. long long 只有正负 2^63-1
  91. */
  92.  
  93.  
  94.  
  95. /*
  96. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
  97. ⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⣴⣤⡀⠀⢀⣀⣤⠤⠤⠶⠖⠒⠒⠒⠒⠒⠲⠶⠤⢤⣀⡀⣼⣛⣧⠀⢁⠀⠀⠀⠀⠀⠀
  98. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣸⣏⢻⣍⠁⠀⢀⡀⠤⠄⠒⠒⠒⠒⠒⠒⠀⠤⠄⠀⠀⢸⡳⢾⢹⡀⠀⠀⠀⠀⠀⠀⠀
  99. ⠀⠀⠀⠀⠀⠀⠀⣠⠖⠋⠀⢯⡞⣎⡆⠁⠀⠀⠀⢀⡀⠀⠤⠤⠤⠤⠄⠀⡀⠀⠀⠻⣽⣻⡌⠹⣄⠀⠐⠀⠀⠀⠀
  100. ⠀⠀⠀⠀⠀⢀⡾⠁⠀⠀⢀⢾⣹⢿⣸⠀⣰⠎⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠆⠹⡿⣏⢆⠈⢷⡀⠀⠆⠀⠀
  101. ⠀⠀⠀⠀⣰⠏⠀⠀⢀⠔⠛⠄⠙⠫⠇⢀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢄⠠⠒⠒⠵⡈⢳⡀⠀⠀⠀
  102. ⠀⠄⠀⡰⠁⠀⠀⢠⠊⠄⠂⠁⠈⠁⠒⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⡀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠄⢳⡀⠈⠀
  103. ⠈⠀⣸⠃⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠀⠐⠀⠀⠐⠀⢀⠀⠀⠀⠀⢷⠀⠀
  104. ⠀⢠⠇⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠀⠀⠀⠀⠀⠰⠀⠀⠀⠀⠀⠀⡄⠀⡀⠆⢰⠀⠀⠀⡄⠀⠀⠀⠸⡄⠀
  105. ⠀⣼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠉⠀⡄⠀⢀⠀⠀⡄⠂⠆⠀⠀⠀⠀⢁⠀⢁⠀⢸⠀⢇⠀⡇⠀⠀⠀⠀⣧⠀
  106. ⠀⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠰⡃⠄⠈⡄⠀⡇⢀⢰⠀⠀⠀⠀⡼⠀⠸⢰⠀⣤⣅⣁⣴⠀⠀⠀⠀⢻⠀
  107. ⢠⡇⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠱⢀⣁⣤⣧⣴⣧⣄⡇⢸⣸⡄⠀⢀⣆⠀⣦⠊⢹⣿⣿⡛⠻⢿⠀⠀⠀⠀⢸⡇
  108. ⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⣃⠀⠀⢴⣿⠟⠉⢈⣿⣿⣿⡟⠇⠀⠀⠀⠀⠀⠀⢸⣶⣿⣿⡿⣧⠀⢸⡇⠀⢃⠀⢸⡇
  109. ⠈⡇⠀⠀⠀⠀⠀⠀⠀⡀⢉⡄⠀⢸⠁⠀⣷⣾⣿⣿⡟⣿⠀⠀⠀⠀⠀⠀⠀⠀⢧⠙⠋⢁⡟⢀⡦⢧⠀⠸⡇⢸⡇
  110. ⠀⣿⠀⠀⠀⠀⠀⠀⢀⠔⠪⡄⠀⠸⣁⠀⠹⣉⠉⠉⢠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠈⠓⢲⠛⠆⢉⠀⢸⠀⢀⢇⢸⡇
  111. ⠀⢿⠀⠀⠀⠀⠀⢀⠃⡐⠐⣴⠀⠀⠏⠉⠖⠉⠋⡙⠁⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⢀⡠⠀⠊⠄⠌⢘⠀⠀⠸⢸⠀
  112. ⠀⢸⠀⠀⠀⠀⠀⠈⣆⢃⠘⠘⡀⠀⡸⡘⡐⡐⠠⠁⠀⡴⡖⣲⠒⠊⠉⠉⠉⠙⢿⣤⡇⠀⠀⠀⠈⢐⠀⠀⠁⣿⠀
  113. ⠀⠘⡇⠀⠀⠀⠀⠀⠈⢶⠬⣁⡇⠀⠀⠑⠐⠤⠐⠀⠀⡇⠉⠀⠀⠀⠀⠀⠀⠀⠀⢙⠇⠀⠀⠀⠀⣼⢀⠀⠀⣿⠀
  114. ⠀⠀⣇⠀⠀⠀⢰⠀⠀⠈⠀⠂⡇⠀⠃⢡⠀⠀⠀⠀⠀⠹⡄⠀⠀⠀⠀⠀⠀⠀⣠⠎⠀⠀⢀⡴⡞⡉⠈⠀⠀⣿⠀
  115. ⠀⠀⣹⠀⠀⠀⠀⠀⠀⠀⠀⡀⡇⠀⢰⠈⡷⡀⠀⠀⠀⠀⠸⢶⣀⠀⠀⢀⣰⠎⠁⢀⡶⠏⠁⣈⠆⠁⡀⠰⢸⡇⠀
  116. ⠀⠀⢸⡀⢸⠀⠀⠆⠀⠀⠀⠀⡇⠀⠀⠀⢡⡄⡏⢆⠒⠢⠤⠤⠤⢨⠥⡴⠒⠚⠉⠉⠀⠀⡠⠁⡘⢠⠁⢀⠆⡇⠀
  117. ⠀⠀⢸⡇⠀⡀⠀⠀⠀⠀⢠⢠⠁⠀⠘⡀⠠⣷⠃⠀⠀⠀⠀⠉⢰⠈⢱⠄⡀⡄⠀⢸⠀⠐⠀⠰⠁⠀⠀⡞⠄⣷⠀
  118. ⠀⠀⠀⣷⠀⡇⠀⠀⠀⠸⠀⡈⠀⠀⢂⠃⠀⡄⠇⠀⠀⠀⠀⠀⢔⠳⠀⠀⠣⠍⠒⠤⣰⠁⢠⠃⢠⠀⠀⠅⠀⢻⡀
  119. ⠀⠀⠀⠉⠀⠁⠀⠀⠀⠀⠀⠁⠀⠀⠈⠀⠀⠁⠈⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠈⠁⠀⠈⠀⠁⠀⠈⠀⠀⠁⠀⠈⠁
  120. */
  121.  
Advertisement
Add Comment
Please, Sign In to add comment