fork download
  1. #include<bits/stdc++.h>
  2. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. #define db double
  4. #define ll long long
  5. #define str string
  6. #define re return
  7. using namespace std;
  8. void bai1()
  9. {
  10. ll s1,s2,v1,v2;
  11. cin>>s1>>v1>>s2>>v2;
  12. if(v1==v2) cout<<-1;
  13. else
  14. {
  15. int t=(s1-s2)/(v2-v1);
  16. if(t<0) cout<<-1;
  17. else cout<<t;
  18. }
  19. }
  20. void bai2()
  21. {
  22. str s,x;
  23. ll res=0;
  24. cin>>s>>x;
  25. while(s.find(x)!= str :: npos)
  26. {
  27. int k=s.find(x);
  28. s.replace(k,x.size(),"_");
  29. res++;
  30. }
  31. cout<<res;
  32. }
  33. void bai3()
  34. {
  35. double x,y,z,h;
  36. cin>>x>>y>>z;
  37. h=z*(x-y);
  38. cout<<(ll)ceil(h/y);
  39. }
  40. ll n,m,k,res;
  41. pair<ll,ll> toado[1002];
  42. void tkiem(ll p,ll &a,pair<ll,ll> &b,pair<ll,ll> &c, ll &d,const map<ll,ll> &pos)
  43. {
  44. c=*pos.upper_bound(p);
  45. if(c.first<n+1) d=(pos.upper_bound(c.first))->first;
  46. b=*(--pos.lower_bound(p));
  47. if(b.first>0) a=(--pos.lower_bound(b.first))->first;
  48. }
  49. void in(ll p,map<ll,ll> &pos,set<pair<ll,ll>,greater<pair<ll,ll>>> &s)
  50. {
  51. ll d=n+10,a=-1,res=++pos[p];
  52. pair<ll,ll> c={0,0},b={0,0};
  53. tkiem(p,a,b,c,d,pos);
  54. if(res>1)
  55. {
  56. s.erase({c.first-b.first-1,b.first});
  57. return;
  58. }
  59. if(a>-1&&b.second==1)
  60. {
  61. s.erase({c.first-a-1,a});
  62. s.insert({p-a-1,a});
  63. }
  64. if(d<n+10&&c.second==1)
  65. {
  66. s.erase({d-b.first-1,b.first});
  67. s.insert({d-p-1,p});
  68. }
  69. s.insert({c.first-b.first-1,b.first});
  70. }
  71. void bai4()
  72. {
  73. ll i,r1,r2,r,c,ma,j;
  74. cin>>m>>n>>k;
  75. for(i=1;i<=k;i++)
  76. {
  77. cin>>r>>c;
  78. toado[i]={r,c};
  79. }
  80. sort(toado+1,toado+k+1);
  81. toado[k+1]={m+1,0};
  82. for(i=1;i<=k;i++)
  83. {
  84. if(toado[i].first>toado[i-1].first)
  85. {
  86. r1=-1;
  87. if(toado[i].first>toado[i-1].first) r1=toado[i-1].first+1;
  88. map<ll,ll> pos;
  89. set<pair<ll,ll>,greater<pair<ll,ll>>> s;
  90. ma=0;
  91. pos.insert({0,1});
  92. pos.insert({n+1,1});
  93. for(j=i;j<=k+1;j++)
  94. {
  95. if(toado[j].first>toado[j-1].first)
  96. {
  97. if(j>1)
  98. {
  99. r2=toado[j].first-1;
  100. ma=(s.begin())->first;
  101. res=max(res,(r2-r1+1)*ma);
  102. if(j<=k) in(toado[j].second,pos,s);
  103. }
  104. else
  105. {
  106. pos[toado[j].second]=1;
  107. s.insert({n,0});
  108. }
  109. }
  110. else in(toado[j].second,pos,s);
  111. }
  112. }
  113. }
  114. cout<<res;
  115. }
  116. void bai5()
  117. {
  118. ll n,i,q,x;
  119. cin>>n;
  120. vector<ll> a(n+1),f(n+1),g(n+1);
  121. for(i=1;i<=n;i++) cin>>a[i];
  122. f[n]=0;
  123. g[n]=a[n];
  124. for(i=n-1;i>0;i--)
  125. {
  126. f[i]=f[i+1]+max(g[i+1]-a[i],0LL);
  127. g[i]=max(g[i+1],a[i]);
  128. }
  129. cin>>q;
  130. while(q--)
  131. {
  132. cin>>x;
  133. cout<<f[x]<<"\n";
  134. }
  135. }
  136. int main()
  137. {
  138. faster
  139. // freopen("DRB.INP","r",stdin);
  140. // freopen("DRB.OUT","w",stdout);
  141. // bai1(); /*max*/
  142. // freopen("ARN.INP","r",stdin);
  143. // freopen("ARN.OUT","w",stdout);
  144. // bai2(); /*max*/
  145. // freopen("TBG.INP","r",stdin);
  146. // freopen("TBG.OUT","w",stdout);
  147. // bai3(); /*max*/
  148. // freopen("HCN.INP","r",stdin);
  149. // freopen("HCN.OUT","w",stdout);
  150. // bai4(); /*max*/
  151. // freopen("VNI.INP","r",stdin);
  152. // freopen("VNI.OUT","w",stdout);
  153. // bai5(); /*max*/
  154. return 0;
  155. }
  156.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty