Advertisement
RaFiN_

cf-629D

Jan 7th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.04 KB | None | 0 0
  1. /*just read the problem and analyze the answer.....
  2.  
  3. As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
  4.  
  5. Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
  6.  
  7. However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where jā€‰<ā€‰i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
  8.  
  9. Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
  10.  
  11.  
  12. */
  13.  
  14.  
  15. ///#include <stdio.h>
  16. ///#include <iostream>
  17. ///#include <cstring>
  18. ///#include <cmath>
  19. ///#include <algorithm>
  20. ///#include <string>
  21. ///#include <vector>
  22. ///#include <map>
  23. ///#include <set>
  24. ///#include <queue>
  25. ///#include <cstdlib>
  26. ///#include <limits>
  27. ///#include <iostream>
  28. ///#include <sstream>
  29. ///#include <unordered_set>
  30. ///#include <unordered_map>
  31. ///#include <random>
  32. #include <bits/stdc++.h>
  33. ///#include <bits/stdtr1c++.h>
  34. ///#include <ext/pb_ds/assoc_container.hpp>
  35. ///#include <ext/pb_ds/tree_policy.hpp>
  36. using namespace std;
  37. ///using namespace __gnu_pbds;
  38.  
  39. #define              MAX             200005
  40. #define              EPS             1e-9
  41. #define              ull             unsigned long long
  42. #define              ll              long long
  43. #define              inf             INT_MAX
  44. #define              pi              acos(-1.0)
  45. #define              vi              vector<int>
  46. #define              vl              vector<long long>
  47. #define              pii             pair<int,int>
  48. #define              pll             pair<long long,long long>
  49. #define              mp              make_pair
  50. #define              mem(a, v)       memset(a, v, sizeof (a))
  51. #define              mod             1000000007
  52. #define              all(a)          a.begin(),a.end()
  53. #define              rall(a)         a.rbegin(),a.rend()
  54. #define              ff              first
  55. #define              ss              second
  56. #define              arsort(ar,n)    sort(ar,ar+n);
  57. #define              vsort(v)        sort(v.begin(),v.end())
  58. #define              vrev(v)         reverse(v.begin(),v.end())
  59. #define              arrev(ar,n)     reverse(ar,ar+n)
  60. #define              pb              push_back
  61. #define              popb            pop_back
  62. #define              booster()       ios_base::sync_with_stdio(0); cin.tie(0);
  63. #define              read(f)         freopen(f, "r", stdin)
  64. #define              scani(x)        scanf("%d",&x)
  65. #define              scanl(x)        scanf("%I64d",&x)
  66. #define              scand(x)        scanf("%lf",&x)
  67. #define              scans(x)        scanf("%s",x)
  68. #define              OUT(x)          printf("%d\n",x)
  69. #define              OUTS(x)         printf("%d ",x)
  70. #define              min3(a,b,c)     min(a,min(b,c))
  71. #define              max3(a,b,c)     max(a,max(b,c))
  72. #define              min4(a,b,c,d)   min(min(a,b),min(c,d))
  73. #define              max4(a,b,c,d)   max(max(a,b),max(c,d))
  74. #define              max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
  75. #define              min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
  76.  
  77. #define              bitCheck(a,k)     ((bool)(a&(1<<(k))))
  78. #define              bitOff(a,k)       (a&(~(1<<(k))))
  79. #define              bitOn(a,k)        (a|(1<<(k)))
  80. #define              bitFlip(a,k)      (a^(1<<(k)))
  81.  
  82. #define              POPCOUNT           __builtin_popcount
  83. #define              POPCOUNTLL         __builtin_popcountll
  84. #define              RIGHTMOST          __builtin_ctzll
  85. #define              LEFTMOST(x)        (63-__builtin_clzll((x)))
  86.  
  87.  
  88.  
  89. #define scani2(a,b) scani(a) , scani(b)
  90. #define scani3(a,b,c) scani(a), scani(b), scani(c)
  91. #define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
  92. #define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
  93. #define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  94.  
  95.  
  96.  
  97. /*********************Ordered Multiset*************************/
  98.  
  99.  
  100. /*** Needs C++11 or C++14 ***/
  101. /// Treap supporting duplicating values in set
  102. /// Maximum value of treap * ADD must fit in long long
  103.  
  104. /*
  105.  
  106. struct Treap{ /// hash = 96814
  107.     int len;
  108.     const int ADD = 1000010;
  109.     const int MAXVAL = 1000000010;
  110.     tr1::unordered_map <long long, int> mp; /// Change to int if only int in treap
  111.     tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> T;
  112.     Treap(){
  113.         len = 0;
  114.         T.clear(), mp.clear();
  115.     }
  116.     inline void clear(){
  117.         len = 0;
  118.         T.clear(), mp.clear();
  119.     }
  120.     inline void insert(long long x){
  121.         len++, x += MAXVAL;
  122.         int c = mp[x]++;
  123.         T.insert((x * ADD) + c);
  124.     }
  125.     inline void erase(long long x){
  126.         x += MAXVAL;
  127.         int c = mp[x];
  128.         if (c){
  129.             c--, mp[x]--, len--;
  130.             T.erase((x * ADD) + c);
  131.         }
  132.     }
  133.     /// 1-based index, returns the K'th element in the treap, -1 if none exists
  134.     inline long long kth(int k){
  135.         if (k < 1 || k > len) return -1;
  136.         auto it = T.find_by_order(--k);
  137.         return ((*it) / ADD) - MAXVAL;
  138.     }
  139.     /// Count of value < x in treap
  140.     inline int count(long long x){
  141.         x += MAXVAL;
  142.         int c = mp[--x];
  143.         return (T.order_of_key((x * ADD) + c));
  144.     }
  145.     /// Number of elements in treap
  146.     inline int size(){
  147.         return len;
  148.     }
  149. };
  150.  
  151.  
  152.  
  153. typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;///*X.find_by_order();X.order_of_key();
  154. template <class T> inline bool isLeap(T y) {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }*/
  155. template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
  156. template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
  157. template <class T> inline T BigMod(T Base,T power,T M=mod){if(power==0)return 1;if(power&1)return ((Base%M)*(BigMod(Base,power-1,M)%M))%M;else{T y=BigMod(Base,power/2,M)%M;return (y*y)%M;}}
  158. template <class T> inline T ModInv (T A,T M = mod){return BigMod(A,M-2,M);}
  159.  
  160. int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
  161. int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
  162. int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  163.  
  164.  
  165. /*********************** let the play begin() ***********************************/
  166.  
  167. int n;ll r[MAX],h[MAX],pum[MAX],I[MAX];
  168.  
  169. vector<pll>v;
  170.  
  171. ll tree[4*MAX];
  172.  
  173. void update(int node,int b,int e,int indx,ll val)
  174. {
  175.     if(b>indx||indx>e)return ;
  176.     if(b==e)
  177.     {
  178.         tree[node] = val;
  179.         return ;
  180.     }
  181.     int mid = (b+e)>>1;
  182.     int left = 2*node;
  183.     int right = left+1;
  184.     update(left,b,mid,indx,val);
  185.     update(right,mid+1,e,indx,val);
  186.  
  187.     tree[node] = max(tree[left] , tree[right]);
  188. }
  189. ll query(int node,int b,int e,int l,int r)
  190. {
  191.     if(b>r||l>e||b>e)return 0;
  192.     if(b>=l&&e<=r)
  193.     {
  194.         return tree[node];
  195.     }
  196.     int mid = (b+e)>>1;
  197.     int left = 2*node;
  198.     int right = left+1;
  199.     ll p1 = query(left,b,mid,l,r);
  200.     ll p2 = query(right,mid+1,e,l,r);
  201.  
  202.     return max(p1 , p2);
  203. }
  204.  
  205. bool cmp(const pll &a,const pll &b)
  206. {
  207.     if(a.ff==b.ff)return a.ss>b.ss;
  208.     return a.ff<b.ff;
  209. }
  210.  
  211. ll sum[MAX],mx;
  212. int main()
  213. {
  214.     booster()
  215.     ///read("input.txt");
  216.     cin>>n;
  217.     for(int i = 0;i<n;i++)
  218.     {
  219.         cin>>r[i]>>h[i];
  220.         v.pb(pll(r[i]*r[i]*h[i],i+1));
  221.     }
  222.  
  223.     sort(all(v),cmp);
  224.     v.pb(pll(0,0));
  225.     for(int i = n;i>=1;i--)v[i] = v[i-1];
  226.     ///for(int i = 1;i<=n;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
  227.     for(int i = 1;i<=n;i++)
  228.     {
  229.         ll x = query(1,1,n,1,v[i].ss) + v[i].ff;
  230.         mx = max(mx,x);
  231.         update(1,1,n,v[i].ss,x);
  232.  
  233.     }
  234.     double ans = pi * 1.0 * mx;
  235.  
  236.     cout<<setprecision(10)<<fixed<<ans;
  237.  
  238.     return 0;
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement