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 ...
随机推荐
- maven 坐标获取方式
问题:我们在开发时pom.xml文件中的 <dependencies> <dependency> <groupId>org.mybatis& ...
- 一个错误导致懂了mac系统的PATH环境变量
一个完全不懂mac系统的强迫症小白,由于搭建环境都按照百度走,所以在执行命令echo $PATH查看PATH内容时发现怎么有这样一串东西 /usr/local/bin:/usr/bin:/bin:/u ...
- hdu 6206 : Apple 【计算几何 + 分数类】
题目链接 比赛时C++上__float128都被卡精度,然后扔给队友用Java的BigDecimal过了 算法不多说,求三角形外心可以参考 维基百科 https://zh.wikipedia.org/ ...
- 重塑云上的 Java 语言
音乐无国界,但是音乐人有国界. 云原生亦如此.虽没有限定的编程语言,但应用所使用的编程语言已经决定了应用部署运行的行为. Java 诞生于20年前,拥有大量优秀的企业级框架,践行 OOP 理念,更多体 ...
- React Native 中不用手点击,代码实现切换底部tabBar
参考:https://www.jianshu.com/p/02c630ed7725 tabBar1页面有按钮,点击切换到tabBar2 直接用this.props.navigation.navigat ...
- 一本通【例题4】Addition Chains——题解
又是一道剪枝剪了半天的搜索题...题目传送 要充分利用题目中的约束条件:1.:2.对于每个k(1≤k≤m)k(1≤k≤m)满足ak=ai+aj(0≤i,j≤k−1)ak=ai+aj(0≤i,j≤k−1 ...
- httpscan 爬虫式的网段Web主机发现小工具
httpscan是一个扫描指定网段的Web主机的小工具.和端口扫描器不一样,httpscan是以爬虫的方式进行Web主机发现,因此相对来说不容易被防火墙拦截.httpscan会返回IP http状态码 ...
- POJ 1383 Labyrinth (bfs 树的直径)
Labyrinth 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/E Description The northern part ...
- leetcode-mid-Linked list-328 Odd Even Linked List-NO
mycode # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # sel ...
- 如何:执行大型 XML 文档的流式转换 大XML文件解析入库的一个方法
w Parsing Huge XML Files Incrementally http://pclib.github.io/safari/program/python-cookbook/Text/ch ...