bzoj-4172 Marbles

Source: Internet
Author: User

Test instructions

Whiteboard questions, omitted;


Exercises

First, according to the operation with splay maintenance sequence;

Note that the sequence after maintenance should be guaranteed to be n;

Then there are three arrays of a[i],p[i],q[i];

F[i] Indicates the maximum score for hitting the I-marbles with the front marbles;

Then F[i]=max (0,-a[i]*p[j]+q[j]);

(0<j<i)

Temporarily do not consider 0, deformation can be q[j]=a[i]*p[j]+f[i];

This is obviously a slope optimization form, maintenance of a convex hull, two points on the convex hull is good;

0 of the situation is to add a point to go in, anyway, will not be t out convex shell;

Two points is not very good to write, but seems to be two minutes to l,r answer to take a max to write more (laughter);

Time complexity O (MLOGN+NLOGN);

This problem is clearly two questions!



Code:


#include <stdio.h> #include <string.h> #include <algorithm> #define N 410000#define which (x) (Ch[fa[x] ][1]==x) using namespace Std;typedef long long ll;int fa[n],ch[n][2],size[n],root,tot,cnt;ll val[n],a[n],x[n],y[n];int N,m,i,st[n],top;char str[100];void pushup (int x) {size[x]=size[ch[x][0]]+size[ch[x][1]]+1;} void Rotate (int x) {int f=fa[x];bool k=which (x); Ch[f][k]=ch[x][!k];ch[x][!k]=f;ch[fa[f]][which (f)]=x;fa[ch[f][k]]=f ; fa[x]=fa[f];fa[f]=x;size[x]=size[f]; Pushup (f);} void splay (int x,int g) {while (fa[x]!=g) {int f=fa[x];if (fa[f]==g) {Rotate (x); if (which (x) ^which (f)) Rotate (x); elserotate (f); Rotate (x);} if (!g) root=x;} int rank (int x,int k) {if (k<=size[ch[x][0])) return rank (ch[x][0],k); else if (k==size[ch[x][0]]+1) return x; Elsereturn rank (ch[x][1],k-size[ch[x][0]]-1);} void Insert (int k,ll v) {int X=rank (root,k), Y=rank (root,k+1); Splay (x,0), splay (y,x); fa[++tot]=y;size[tot]=1;ch[y][0]=tot;val[tot]=v; Pushup (y); Pushup (x);} void change (int k,ll v) {int X=rank (root,k); val[x]=v; Pushup (x);} void Print (int x) {if (!x) return; Print (Ch[x][0]); a[++cnt]=val[x]; Print (ch[x][1]);} Double slope (int a,int b) {if (b>=i) return 0;return (double (y[a]-y[b]))/(X[a]-x[b]);} int main () {int j,k,l,r,mid;ll v;scanf ("%d%d", &n,&m); Tot=2;ch[1][1]=2,fa[2]=1;root=1;for (i=1;i<=m;i++) { scanf ("%s%d%lld", Str,&k,&v), if (str[0]== ' I ') Insert (k+1,v); Elsechange (k+2,v);} Cnt=-1; Print (Root), for (i=1;i<=n;i++) scanf ("%lld%lld", X+i,y+i), St[top=2]=1;for (i=2;i<=n;i++) {l=1,r=top;while (l <=r) {mid=l+r>>1;if (slope (st[mid],st[mid+1]) >a[i]) l=mid+1;elser=mid-1;} printf ("%lld\n", Max (Y[st[l]]-a[i]*x[st[l]],y[st[r]]-a[i]*x[st[r])); while (top>1&& (y[st[top]]-y[st[ TOP-1]]) * (X[i]-x[st[top]]) <= (Y[i]-y[st[top]]) * (X[st[top]]-x[st[top-1]])) top--;st[++top]=i;} return 0;}




bzoj-4172 Marbles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.