首先可以证明,点积最值的点对都是都是在凸包上,套用题解的证明:假设里两个点都不在凸包上, 考虑把一个点换成凸包上的点(不动的那个点), 不管你是要点积最大还是最小, 你都可以把那个不动的点跟原点拉一条直线, 然后把所有的点投影到这条直线上, 要找的无非就是这条直线最前面或者最后面的两个点.这两个点不可能是不在凸包上的点.同理我们可以把另一个点移到凸包上.

由于数据随机生成,那么生成凸包上的点的个数的期望是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(凸包+平衡树)的更多相关文章

  1. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

  2. HDU 2217 Data Structure?

    C - Data Structure? Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. hdu 4217 Data Structure? 树状数组求第K小

    Data Structure? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. hdu 4217 Data Structure?/treap

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4217 可用线段树写,效率要高点. 这道题以前用c语言写的treap水过了.. 现在接触了c++重写一遍 ...

  5. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

  6. [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 ...

  7. [hdu7097]Just a Data Structure Problem

    (四边形不等式的套路题) 对于某一组$a_{i}$,显然可以区间dp,设$f_{l,r}$表示区间$[l,r]$​的答案,则转移即$$f_{l,r}=\begin{cases}0&(l=r)\ ...

  8. HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. font-awesome样式只显示方框

    这是一个踩过的坑:使用font-awesome中的css样式库时,比如fa-user-circle-o,显示的不是一个用户图标,而是一个方框. 怎么回事呢? 进入css文件,发现: 咦,这些文件呢?我 ...

  2. python multiprocessing pool

    python 本身是不是单线程这个我真心搞不懂 但是我是来吐槽的: multiprocessing.Pool(precesses = 2) 这个语句曾经让我的内存爆满,死机不解释. 在重装 pytho ...

  3. SQL 介绍和操作

    1.什么是SQL SQL的全称是“结构话查询语句”(Structured Query Language ),是1974年有Boyce和chamberlin 提出来的.经过多年的发展,SQL语言已经成为 ...

  4. #433 Div2 Problem C Planning (贪心 && 优先队列)

    链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...

  5. 软件安装——彻底卸载MySQL

    如果你的电脑里装过MySQL,想再重新安装MySQL的时候可能就会因为前一版本卸载不彻底而出现错误.最常见的就是安装好后设置参数的最后一步验证时,会在Execute configurattion步骤中 ...

  6. 安装k8s集群(亲测)

    先安装一台虚拟机,然后进行克隆,因为前面的步骤都是一样的,具体代码如下: Last login: Mon Nov 25 00:40:34 2019 from 192.168.180.1 ##安装依赖包 ...

  7. (24)Python实现递归生成或者删除一个文件目录及文件

    def removeDir(dirPath): ''' Created by Wu Yongcong 2017-8-18 :param dirPath: :return: ''' if not os. ...

  8. bat语法

    注释 :: 注释无回显 rem 注释有回显 关闭和开启回显 :: 关闭回显 @echo off echo abc :: 开启回显 echo on echo 查看命令帮助说明 rd /? 目录操作 创建 ...

  9. MySQL删除外键约束问题

    当我们在一个表中添加字段约束的时候: ALTER TABLE product ADD CONSTRAINT product_fk FOREIGN KEY(category_id) REFERENCES ...

  10. Web网站安全

    一.防SQL注入 SQL注入,就是在web提交表单,请求参数的字符串中通过注入SQL命令,提交给服务器,从而让服务器执行注入的恶意的SQL命令的行为,是发生在开发程序的数据库层的安全漏洞. SQl注入 ...