Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <set>
- #include <cstring>
- #include <map>
- #include <cstdlib>
- #include <ctime>
- #include <cassert>
- #include <bitset>
- #define f first
- #define s second
- #define ll long long
- #define ull unsigned long long
- #define mp make_pair
- #define pb push_back
- #define vi vector <int>
- #define ld long double
- #define pii pair<int, int>
- using namespace std;
- const int N = int(6e5);
- int n,m;
- int a[N],b[N];
- int c[N],d[N],qn,pn;
- pair <pair<int,int> ,int > q[N];
- ll ans[N];
- pair <int,int> pp[N],p[N];
- int mnc,mnd,k;
- pair <int,int> line[N];
- ld x1,x2;
- int it;
- bool cmp(pair <pair<int,int> ,int > a, pair <pair<int,int> ,int > b){
- 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));
- }
- void addline(pii p){
- while(k > 1){
- 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;
- k--;
- }
- line[++k] = p;
- }
- ll find_max(ll a,ll b){
- while(it < k){
- if(1ll*(line[it+1].s - line[it].s) * b >= 1ll*(line[it].f - line[it+1].f) * a) break;
- it++;
- }
- return 1ll * a * line[it].f + 1ll * line[it].s * b;
- }
- int main () {
- //freopen("in","r",stdin);
- //freopen("out","w",stdout);
- scanf("%d",&n);
- for(int i=1;i<=n;i++){
- scanf("%d%d",&a[i],&b[i]);
- }
- scanf("%d",&m);
- mnc = int(1e9),mnd = int(1e9);
- for(int i=1;i<=m;i++){
- scanf("%d%d",&p[i].f,&p[i].s);
- mnc = min(mnc,p[i].f);
- mnd = min(mnd,p[i].s);
- }
- sort(p+1,p+m+1);
- reverse(p+1,p+m+1);
- for(int i=1;i<=n;i++){
- if(!a[i]){
- ans[i] = 1ll * b[i] * mnd;
- }
- else if(!b[i]){
- ans[i] = 1ll * a[i] * mnc;
- }
- else {
- q[++qn] = mp(mp(a[i],b[i]),i);
- }
- }
- k = 0;
- for(int i=1;i<=m;i++){
- addline(p[i]);
- }
- it = 1;
- sort(q+1,q+qn+1,cmp);
- for(int i=1;i<=qn;i++){
- ans[q[i].s] = find_max(q[i].f.f,q[i].f.s);
- }
- for(int i=1;i<=n;i++){
- printf("%lld ",ans[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement