Advertisement
Wxydth

Count the Chaos

May 30th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <set>
  2. #include <map>
  3. #include <ctime>
  4. #include <queue>
  5. #include <cmath>
  6. #include <stack>
  7. #include <vector>
  8. #include <valarray>
  9. #include <cstdio>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cstdlib>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <ext/pb_ds/assoc_container.hpp>
  16. #include <ext/pb_ds/tree_policy.hpp>
  17. using namespace __gnu_pbds;
  18. using namespace std;
  19. typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  20.  
  21. typedef long long ll;
  22. string text="abcdefghijklmnopqrstuvwxyz";
  23. const int maxn=1e6+7;
  24. // .--------------.
  25. // | Try First One|
  26. // '--------------'
  27. // | .--------------.
  28. // | | |
  29. // V V |
  30. // .--------------. |
  31. // | AC. |<---. |
  32. // '--------------' | |
  33. // (True)| |(False) | |
  34. // .--------' | | |
  35. // | V | |
  36. // | .--------------. | |
  37. // | | Try Again |----' |
  38. // | '--------------' |
  39. // | |
  40. // | .--------------. |
  41. // '->| Try Next One |-------'
  42. // '--------------'
  43. int main()
  44. {
  45. ios_base::sync_with_stdio(false);
  46. cin.tie(NULL);
  47. ordered_set s;
  48. int n;
  49. cin>>n;
  50. int a[n+1];
  51. for(int i=0;i<n;i++)cin>>a[i];
  52. s.insert(a[0]);
  53. int ans=0;
  54. for(int i=1;i<n;i++){
  55. s.insert(a[i]);
  56. ans+=s.size()-(s.order_of_key(a[i]+1));
  57. }
  58. cout<<ans;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement