fork download
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #define ll long long int
  5. #define fi first
  6. #define se second
  7. #define pi acos(-1.0)
  8. #define pb push_back
  9. #define B begin
  10. #define E end
  11. #define mod 1000000007
  12. #define YY cout<<"YES"<<endl
  13. #define NN cout<<"NO"<<endl
  14. #define Yy cout<<"Yes"<<endl
  15. #define Nn cout<<"No"<<endl
  16. #define yy cout<<"yes"<<endl
  17. #define nn cout<<"no"<<endl
  18. #define MX 4*10e18
  19. #define NODES 100000
  20. #define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  21. using namespace std;
  22.  
  23. using namespace __gnu_pbds;
  24.  
  25. template<class T>
  26. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
  27. priority_queue<ll,vector<ll>,greater<ll> > san;
  28.  
  29. bool sortBysec(pair<ll,ll>a,pair<ll,ll>b)
  30. {
  31. return a.second>b.second;
  32. }
  33.  
  34.  
  35.  
  36. int main()
  37. {
  38. FAST();
  39. ll t=1,tt=0,i,j,k,n,m,x,y,z,a,b,c,d,ans,p,q,f;
  40.  
  41. //cin>>t;
  42.  
  43. while(t--)
  44. {
  45. tt++;
  46. ordered_set<ll>os;
  47. cin>>n;
  48. vector<ll>v;
  49. for(i=0;i<n;i++)
  50. {
  51. cin>>x;
  52. v.pb(x);
  53. }
  54. ll ans=0;
  55. for(i=0;i<n-1;i++)
  56. {
  57. p=os.order_of_key(v[i]);
  58. x=v[i]-1;
  59. //cout<<v[i]<<" "<<p<<endl;
  60. ans+=max(0ll,(x-p));
  61. os.insert(v[i]);
  62. }
  63. cout<<ans<<endl;
  64. }
  65.  
  66. return 0;
  67. }
  68.  
Runtime error #stdin #stdout 2.66s 2095820KB
stdin
Standard input is empty
stdout
Standard output is empty