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

由于数据随机生成,那么生成凸包上的点的个数的期望是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. Python之常用模块一(主要RE和collections)

    一.认识模块  什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是加上.py的后缀,但其实import加载的模块分为四个通用类别 : 1.使用python编写的代码(.py文件 ...

  2. python-类对象的比较

    #类对象的比较 class Person: def __init__(self,age,height): self.age=age self.height=height def __eq__(self ...

  3. 部署至Oracle数据库的注意事项

    部署至Oracle数据库的注意事项 安装数据库之前1)检查计算机名,如果是乱码,改一下名字 2)有杀毒软件,能关则关               但是最好征求用户的同意 3)装两个一起解压databa ...

  4. js 将时间戳转为日期格式

    最近项目需要在前端将一个13位的时间戳显示成日期格式,在网上查了很多都不符合要求,只有一个是能满足要求的,在这记录一下,说不定以后还用的着. 13位时间戳改为yyyy-MM-dd HH-mm-ss 格 ...

  5. 状态管理工具对比vuex、redux、flux

    1.为什么要使用状态管路工具  在跨层级的组件之间传递信息,尤其是复杂的组件会非常困难.也不利于开发和维护,这时我们就a需要用到状态管理工具.     2.Flux

  6. CF889E Mod Mod Mod

    http://codeforces.com/problemset/problem/889/E 题解 首先我们观察到在每次取模的过程中一定会有一次的结果是\(a_i-1\),因为如果不是,我们可以调整, ...

  7. Online Game Development in C++ 第五部分总结

    I. 教程案例框架描述 该套教程做了一个简单的汽车控制系统,没有用到物理模拟.用油门和方向控制汽车的加速度和转向,同时还有一些空气阻力和滚动摩擦力的设置增加了真实感.汽车的位置是通过加速度和时间等计算 ...

  8. 学习日记18、easyui 文件框上传文件

    前台 <tr> <td style="width:100px; text-align:right;"> @Html.LabelFor(model => ...

  9. Vue包的下载

    第一步:先去官网下载Vue包:https://cn.vuejs.org/,找到教程. 第二步:Vue的包有以下引入方式(点击之后,跳转页面,直接将代码复制下来,放到新文件中,另存为即可使用Vue.js ...

  10. leetcode-mid-array-5. Longest Palindromic Substring

    mycode   12.51% class Solution(object): def longestPalindrome(self, s): """ :type s: ...