Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <vector>
  7. #include <stack>
  8. #include <queue>
  9. #include <set>
  10. #include <cstring>
  11. #include <map>
  12. #include <cstdlib>
  13. #include <ctime>
  14. #include <cassert>
  15. #include <bitset>
  16. #define f first
  17. #define s second
  18. #define ll long long
  19. #define ull unsigned long long
  20. #define mp make_pair
  21. #define pb push_back
  22. #define vi vector <int>
  23. #define ld long double
  24. #define pii pair<int, int>
  25. using namespace std;
  26. const int N = int(6e5);
  27. int n,m;
  28. int a[N],b[N];
  29. int c[N],d[N],qn,pn;
  30. pair <pair<int,int> ,int > q[N];
  31. ll ans[N];
  32. pair <int,int> pp[N],p[N];
  33. int mnc,mnd,k;
  34. pair <int,int> line[N];
  35. ld x1,x2;
  36. int it;
  37.  
  38. bool cmp(pair <pair<int,int> ,int > a, pair <pair<int,int> ,int > b){
  39. return (1ll * a.f.f * b.f.s < 1ll * a.f.s * b.f.f || (1ll * a.f.f * b.f.s < 1ll * a.f.s * b.f.f && b.f.f < b.f.s));
  40. }
  41.  
  42. void addline(pii p){
  43. while(k > 1){
  44. if(1ll * (line[k].s - line[k-1].s) * (line[k].f - p.f) < 1ll * (line[k-1].f - line[k].f) * (p.s - line[k].s)) break;
  45. k--;
  46. }
  47. line[++k] = p;
  48. }
  49.  
  50. ll find_max(ll a,ll b){
  51. while(it < k){
  52. if(1ll*(line[it+1].s - line[it].s) * b >= 1ll*(line[it].f - line[it+1].f) * a) break;
  53. it++;
  54. }
  55. return 1ll * a * line[it].f + 1ll * line[it].s * b;
  56. }
  57.  
  58.  
  59.  
  60. int main () {
  61. //freopen("in","r",stdin);
  62. //freopen("out","w",stdout);
  63. scanf("%d",&n);
  64. for(int i=1;i<=n;i++){
  65. scanf("%d%d",&a[i],&b[i]);
  66. }
  67. scanf("%d",&m);
  68. mnc = int(1e9),mnd = int(1e9);
  69. for(int i=1;i<=m;i++){
  70. scanf("%d%d",&p[i].f,&p[i].s);
  71. mnc = min(mnc,p[i].f);
  72. mnd = min(mnd,p[i].s);
  73. }
  74. sort(p+1,p+m+1);
  75. reverse(p+1,p+m+1);
  76. for(int i=1;i<=n;i++){
  77. if(!a[i]){
  78. ans[i] = 1ll * b[i] * mnd;
  79. }
  80. else if(!b[i]){
  81. ans[i] = 1ll * a[i] * mnc;
  82. }
  83. else {
  84. q[++qn] = mp(mp(a[i],b[i]),i);
  85. }
  86. }
  87. k = 0;
  88. for(int i=1;i<=m;i++){
  89. addline(p[i]);
  90. }
  91. it = 1;
  92. sort(q+1,q+qn+1,cmp);
  93. for(int i=1;i<=qn;i++){
  94. ans[q[i].s] = find_max(q[i].f.f,q[i].f.s);
  95. }
  96. for(int i=1;i<=n;i++){
  97. printf("%lld ",ans[i]);
  98. }
  99.  
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement