fork download
  1. /*
  2. A. Ribbon on the Christmas Present
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/tree_policy.hpp>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8.  
  9. using namespace std;
  10. using namespace __gnu_pbds;
  11.  
  12. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > pbds;
  13. // find_by_order, order_by_key
  14.  
  15. #define sp << " " <<
  16. #define ll long long
  17. #define ld long double
  18. #define pb push_back
  19. #define F first
  20. #define S second
  21. #define PI 3.1415926535897932384626
  22.  
  23. #define all(x) x.begin(), x.end()
  24. #define rall(x) x.rbegin(), x.rend()
  25. #define sortall(x) sort(all(x))
  26. #define sortrall(x) sort(rall(x))
  27.  
  28. #define printv(v) for(auto x : v) cout << x << " "; cout << "\n"
  29. #define printm(m) for(auto x : m) cout << x.F sp x.S << "\n"
  30.  
  31. #define make_unique(x) sortall(x); (x).resize(unique(all(x)) - (x).begin())
  32. #define numtobin(n) bitset<32>(n).to_string()
  33. #define bintoint(bin_str) stoi(bin_str, nullptr, 2)
  34.  
  35. struct custom_hash {
  36. static uint64_t splitmix64(uint64_t x) {
  37. x += 0x9e3779b97f4a7c15;
  38. x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  39. x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  40. return x ^ (x >> 31);
  41. }
  42.  
  43. size_t operator()(uint64_t x) const {
  44. static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  45. return splitmix64(x + FIXED_RANDOM);
  46. }
  47. };
  48.  
  49. template<typename T1, typename T2>
  50. using safe_map = unordered_map<T1, T2, custom_hash>;
  51.  
  52. template<typename T>
  53. using safe_set = unordered_set<T, custom_hash>;
  54.  
  55. template<typename T>
  56. void debug(T x) { cerr << x << endl; }
  57.  
  58. template<typename T, typename... Args>
  59. void debug(T x, Args... args) { cerr << x << " "; debug(args...); }
  60.  
  61. void fastIO() {
  62. ios_base::sync_with_stdio(false);
  63. cin.tie(NULL); cout.tie(NULL);
  64. }
  65.  
  66. void fraction() {
  67. cout.unsetf(ios::floatfield);
  68. cout.precision(10);
  69. cout.setf(ios::fixed,ios::floatfield);
  70. }
  71.  
  72. void yn(bool res, bool cap = true) {
  73. vector<string> s = {"Yes", "YES", "No", "NO"};
  74. cout << ((res) ? s[0 + cap] : s[2 + cap]) << "\n";
  75. }
  76.  
  77. void chmin(ll &x, ll y) { x = min(x, y); }
  78. void chmax(ll &x, ll y) { x = max(x, y); }
  79.  
  80. inline ll nxt() { ll x; cin >> x; return x;}
  81. inline ld nxtD() { ld x; cin >> x; return x;}
  82. inline string nxtStr() { string x; cin >> x; return x;}
  83.  
  84. const int mod = 1e9 + 7;
  85. const int INF = 1e9;
  86. const ll LINF = 1e18;
  87.  
  88. void proc(){
  89.  
  90. }
  91.  
  92. void solve() {
  93. int n; cin >> n;
  94. vector<int> v(n+1, INT_MIN);
  95. set<int> s;
  96. for(int i = 0; i < n; i++) {
  97. cin >> v[i];
  98. s.insert(v[i]);
  99. }
  100. int ans = 0;
  101. for(auto x : s) {
  102. bool p = false;
  103. for(auto y : v) {
  104. if(y == x && !p) p = true;
  105. else if(y >= x && p) continue;
  106. else {
  107. ans += p;
  108. p = false;
  109. }
  110. // debug(x, ans, cnt);
  111. }
  112. }
  113.  
  114. cout << ans << "\n";
  115. }
  116.  
  117. int main() {
  118. fastIO();
  119. proc();
  120.  
  121. int tc = 1;
  122. // tc = nxt();
  123. for (int t = 1; t <= tc; t++) {
  124. // cout << "Case " << t << ": ";
  125. solve();
  126. }
  127. }
  128.  
  129.  
Success #stdin #stdout 0.01s 5328KB
stdin
10
1 20 100 1 20 20 100 100 20 20
stdout
5