我們發現如下結論:

1.只有編號小的點才會對編號大的點產生影響

2.當當前點的y坐標大小為1~i最大的,則不會被以前的點影響

於是,維護一個斜率單調遞增的隊列

當當前點的y坐標大小為1~i最大的,則這個點的b值為i

否則,不斷刪去隊列尾部的點,直到隊尾的點y值大於現在的點,輸出隊尾的點的編號

為什麼?因為隊尾的點的y值是1~i-1的點中最後一個y值比現在點大的,我們這個點雖然被前面的點更新,但是更新它最後一個點是隊尾的點

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,x[1000010],y[1000010],st[1000010],ct,mn,b[1000010];
int main(){
	freopen("beatall.in","r",stdin);
	freopen("beatall.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	mn=-2e9;
	for(int i=1;i<=n;i++){
		if(y[i]>=mn){
			mn=y[i];
			ct=0;
			st[++ct]=i;
			b[i]=i;
		}
		else{
			while(ct&&((long long)(y[st[ct-1]]-y[st[ct]])*(x[st[ct]]-x[i]))<=((long long)(x[st[ct-1]]-x[st[ct]])*(y[st[ct]]-y[i])))ct--;
			b[i]=st[ct];
			st[++ct]=i;
		}
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",b[i]);
}

jzoj5950的更多相关文章

随机推荐

  1. Stripies

    /* Our chemical biologists have invented a new very useful form of life called stripies (in fact, th ...

  2. wdk Windows驱动开发

    https://www.cnblogs.com/liaoguifa/p/9049859.html 安装wdk8.1

  3. process概念

    multiprocess: multiprocess.cpu_count():统计cpu核数 multiprocess.active_chirdren():获取所有的子进程 multiprocess. ...

  4. tomcat 时间相差8个小时,百度上查到的,备份下

    通常网上一查都是 修改 tomcat 的参数 ,如catalina 文件,jvm parameters 等.如果都不起作用,可以使用如下方式.. 你可以修改jdk的时间校正了,你这么来.进入 \hom ...

  5. install pip(mac)

    simple method:  sudo easy_install pip you have done!and can install the other py programs using pip ...

  6. Windows10(uwp)开发中的侧滑

    还是在持续的开发一款Windows10的应用中,除了上篇博客讲讲我在Windows10(uwp)开发中遇到的一些坑,其实还有很多不完善的地方,比如(UIElement.Foreground).(Gra ...

  7. 27. Green Building 绿色建筑

    27. Green Building 绿色建筑 ①When we think of green buildings,we tend to think of new ones-the kind of h ...

  8. Django入门与实践-第13章:表单处理(完结)

    http://127.0.0.1:8000/boards/1/ http://127.0.0.1:8000/boards/2/ http://127.0.0.1:8000/boards/3/ http ...

  9. BSD Socket 通信

    Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain ...

  10. (小数化分数)小数化分数2 -- HDU --1717

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1717 举例: 0.24333333…………=(243-24)/900=73/3000.9545454…… ...