HDU 6649 Data Structure Problem(凸包+平衡树)
首先可以证明,点积最值的点对都是都是在凸包上,套用题解的证明:假设里两个点都不在凸包上, 考虑把一个点换成凸包上的点(不动的那个点), 不管你是要点积最大还是最小, 你都可以把那个不动的点跟原点拉一条直线, 然后把所有的点投影到这条直线上, 要找的无非就是这条直线最前面或者最后面的两个点.这两个点不可能是不在凸包上的点.同理我们可以把另一个点移到凸包上.
由于数据随机生成,那么生成凸包上的点的个数的期望是logn,而且删的点落在凸包上的概率是logn/n,所以只需要对每次删点和加点暴力重构凸包即可。但是删点过程要求剩下的第k个还在的点,那么这就需要用平衡树去维护第k个点的值,直接用stl内部的红黑树。
// ——By DD_BOND #include<ext/pb_ds/assoc_container.hpp>
//#include<bits/stdc++.h>
//#include<unordered_map>
//#include<unordered_set>
#include<functional>
#include<algorithm>
#include<iostream>
//#include<ext/rope>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define MP make_pair
#define pb push_back #pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std;
using namespace __gnu_pbds;
using Tree=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const int lim=1e9;
const ll LLMAX=2e18;
const int MAXN=2e5+;
const double eps=1e-;
const double pi=acos(-1.0);
const unsigned mul=;
const ll INF=0x3f3f3f3f3f3f3f3f; inline int dcmp(double x){
if(fabs(x)<eps) return ;
return (x>? : -);
} inline double sqr(double x){ return x*x; } Tree t; struct Point{
ll x,y; int id;
Point(){ x=,y=; }
Point(ll _x,ll _y):x(_x),y(_y){}
bool operator ==(const Point &b)const{
return x==b.x&&y==b.y;
}
bool operator <(const Point &b)const{
return (x-b.x)==? (y-b.y)< : x<b.x;
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
}; inline ll cross(Point a,Point b){ //叉积
return a.x*b.y-a.y*b.x;
} inline ll dot(Point a,Point b){ //点积
return a.x*b.x+a.y*b.y;
} Point tmp[MAXN];
int convex_hull(Point *p,int n,Point *ch){ //求凸包
int m=;
sort(p,p+n);
for(int i=;i<n;i++){
while(m>&&cross(tmp[m-]-tmp[m-],p[i]-tmp[m-])<=) m--;
tmp[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--){
while(m>k&&cross(tmp[m-]-tmp[m-],p[i]-tmp[m-])<=) m--;
tmp[m++]=p[i];
}
if(n>) m--;
for(int i=;i<m;i++) ch[i]=tmp[i];
return m;
} class Magic{
public:
Magic(unsigned state):state(state),ans(){}
unsigned long long retrieve(){
unsigned modulo=0x7fffffff;
state=((unsigned long long)state*mul+ans)%modulo;
unsigned high=state;
state=((unsigned long long)state*mul+ans)%modulo;
return high*modulo+state;
}
int retrieve(int a,int b){
return (int)(retrieve()%(b-a+))+a;
}
void submit(unsigned k){
ans=ans*mul+k;
}
unsigned retrieveAns(){
return ans;
}
private:
unsigned state,ans;
}; class DataStructure{
public:
int n,m;
Point point[MAXN],rec[MAXN];
DataStructure(){ n=m=; }
void add(int x,int y){
t.insert(++m);
rec[m]=Point(x,y);
point[n]=Point(x,y);
point[n++].id=m;
n=convex_hull(point,n,point);
}
void erase(int r){
r=*t.find_by_order(r-);
t.erase(r);
for(int i=;i<n;i++)
if(point[i].id==r){
n=;
for(auto i:t) point[n]=rec[i],point[n++].id=i;
n=convex_hull(point,n,point);
break;
}
}
P query(){
P ans(,); ll len=LLMAX;
for(int i=;i<n;i++)
for(int j=;j<n;j++){
ll dis=dot(point[i],point[j]);
if(dis<len){
len=dis;
ans=P(point[i].id,point[j].id);
}
}
if(ans.fi>ans.se) swap(ans.fi,ans.se);
return ans;
}
}; int main(void){
int q; cin>>q;
for(int k=;k<q;++k){
t.clear();
unsigned state; string s; cin>>state>>s;
DataStructure ds; Magic magic(state);
for(char c:s){
if(c=='a'){
int x=magic.retrieve(-lim,lim);
int y=magic.retrieve(-lim,lim);
ds.add(x,y);
}
else if(c=='e'){
unsigned pos = magic.retrieve(,t.size());
ds.erase(pos);
}
else if(c=='q'){
auto best=ds.query();
magic.submit(best.first);
magic.submit(best.second);
}
}
cout<<magic.retrieveAns()<<endl;
}
}
HDU 6649 Data Structure Problem(凸包+平衡树)的更多相关文章
- CDOJ 483 Data Structure Problem DFS
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
- HDU 2217 Data Structure?
C - Data Structure? Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- hdu 4217 Data Structure? 树状数组求第K小
Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 4217 Data Structure?/treap
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4217 可用线段树写,效率要高点. 这道题以前用c语言写的treap水过了.. 现在接触了c++重写一遍 ...
- ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)
题目链接 ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...
- [hdu7099]Just Another Data Structure Problem
不难发现,问题即求满足以下条件的$(i,j)$对数: 1.$1\le i<j\le n$且$a_{i}=a_{j}$ 2.$\min_{i\le k\le j}y_{k}\ge l$且$\max ...
- [hdu7097]Just a Data Structure Problem
(四边形不等式的套路题) 对于某一组$a_{i}$,显然可以区间dp,设$f_{l,r}$表示区间$[l,r]$的答案,则转移即$$f_{l,r}=\begin{cases}0&(l=r)\ ...
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- java日志文件log4j.properties配置详解
一.Log4j配置 第一步:加入log4j-1.2.8.jar到lib下. 第二步:在CLASSPATH下建立log4j.properties.内容如下: 放在src下的话就不用配置 否则得去web. ...
- man du
DU(1) User Commands/用户命令 DU(1) NAME/名字 du - estimat ...
- 关于Vuex的actions传入多个参数的方法:
1.在state中: state={ obj:{ name:'state中的数据' } } 2.在actions定义的方法中: ...
- BZOJ 5129: [Lydsy1712月赛]树上传送 点分树+Dijkstra
Description http://www.lydsy.com/JudgeOnline/upload/201712/prob12.pdf Input Output 暑假集训的时候点分树做的比较少,所 ...
- POJ 3691 DNA repair ( Trie图 && DP )
题意 : 给出 n 个病毒串,最后再给出一个主串,问你最少改变主串中的多少个单词才能使得主串中不包含任何一个病毒串 分析 : 做多了AC自动机的题,就会发现这些题有些都是很套路的题目.在构建 Trie ...
- SQL ORDER BY 两个列
ORDER BY 后可加2个字段,用英文逗号隔开. f1用升序, f2降序,sql该这样写 ORDER BY f1, f2 DESC 也可以这样写,更清楚: ORDER BY f1 ASC, ...
- [转]Linux下防止进程使用swap及防止OOM机制导致进程被kill掉
首先解释两个概念:swap:在linux里面,当物理内存不够用了,而又有新的程序请求分配内存,那么linux就会选择将其他程序暂时不用的数据交换到物理磁盘上(swap out),等程序要用的时候再读进 ...
- springBoot项目常用maven依赖以及依赖说明
springBoot项目常用maven依赖以及依赖说明 1:maven-compiler-plugin <build> <plugins> <!-- 指定maven编译的 ...
- 20160520—JS打分控件
效果预览: 可实现功能:鼠标在滑动条内左右滑动,文本框内分数变动:文本框输入数字,滑动条长度自动改变. JavaScript代码: $(function () { scoreFun($("# ...
- Swagger入门教程(转)
[译]5.41 Swagger tutorial 单击此处查看原文 更多概念参见:Implementing Swagger with your API docs 关于 Swagger Swagger能 ...