jainbot27

sleepygold

Jul 22nd, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target("sse4")
  3. #include <bits/stdc++.h>
  4. #define f first
  5. #define s second
  6. #define pb push_back
  7. #define mp make_pair
  8. #define ts to_string
  9. #define ub upper_bound
  10. #define lb lower_bound
  11. const char nl = '\n';
  12. using namespace std;
  13. using ll = long long;
  14. using vi = vector<int>;
  15. using vl = vector<ll>;
  16. using pii = pair<int, int>;
  17. using pll = pair<ll, ll>;
  18. using str = string;
  19. //The following debugging code was taken from Benjamin Qi's template :)
  20. str ts(char c) { return str(1,c); }
  21. str ts(bool b) { return b ? "true" : "false"; }
  22. str ts(const char* s) { return (str)s; }
  23. str ts(str s) { return s; }
  24. template<class A> str ts(complex<A> c) {
  25.     stringstream ss; ss << c; return ss.str(); }
  26. str ts(vector<bool> v) {
  27.     str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
  28.     res += "}"; return res; }
  29. template<size_t SZ> str ts(bitset<SZ> b) {
  30.     str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
  31.     return res; }
  32. template<class A, class B> str ts(pair<A,B> p);
  33. template<class T> str ts(T v) {
  34.     bool fst = 1; str res = "{";
  35.     for (const auto& x: v) {
  36.         if (!fst) res += ", ";
  37.         fst = 0; res += ts(x);
  38.     }
  39.     res += "}"; return res;
  40. }
  41. template<class A, class B> str ts(pair<A,B> p) {
  42.     return "("+ts(p.f)+", "+ts(p.s)+")"; }
  43. void DBG() { cerr << "]" << endl; }
  44. template<class H, class... T> void DBG(H h, T... t) {
  45.     cerr << ts(h); if (sizeof...(t)) cerr << ", ";
  46.     DBG(t...); }
  47.  
  48. #ifdef LOCAL
  49. #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
  50. #else
  51. #define dbg(...) 0
  52. //freopen(".in", "r", stdin);
  53. //freopen(".out", "w", stdout);
  54. #endif
  55. //CODE STARTS HERE-----------------------------------------------------------------------------------------//
  56. #include <ext/pb_ds/tree_policy.hpp>
  57. #include <ext/pb_ds/assoc_container.hpp>
  58. using namespace __gnu_pbds;
  59. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  60. const int N = 1e5 + 10;
  61. int n, p[N];
  62. signed main(){
  63.     cin.tie(nullptr);
  64.     ios_base::sync_with_stdio(false);
  65.     ifstream cin("sleepy.in");
  66.     ofstream cout("sleepy.out");
  67.     cin >> n;
  68.     for(int i = 0; i < n; i++)
  69.         cin >> p[i];
  70.     int last = -1;
  71.     for(int i= 0; i < n-1; i++){
  72.         if(p[i]>p[i+1]){
  73.             last = i;
  74.         }
  75.     }
  76.     cout << last+1 << nl;
  77.     ordered_set a;
  78.     for(int i = last+1; i<n; i++){
  79.         a.insert(p[i]);
  80.     }
  81.     for(int i =0 ; i <= last; i++){
  82.         cout << a.order_of_key(p[i])+ n - a.size()-1 << (i!=last?" ":"");
  83.         a.insert(p[i]);
  84.     }
  85. }
Add Comment
Please, Sign In to add comment