BZOJ2773
2015-08-25 20:50
344 查看
传送门:BZOJ2773
以y为key建树,维护最大值,树上二分即可。
吐槽一下学校评测机,我艹我在bzoj上AC的代码T完了。
代码上的小细节见下。
以y为key建树,维护最大值,树上二分即可。
吐槽一下学校评测机,我艹我在bzoj上AC的代码T完了。
代码上的小细节见下。
[code]#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include <iostream> #include <set> #include <map> using namespace std; struct People{ int A,B; int ord; bool operator <(const People& a)const{ return B<a.B||(B==a.B&&A<a.A); } People(){ A=B=0; ord=0; } People(int A_,int B_,int ord_){ A=A_; B=B_; ord=ord_; } }; struct People2{ int A,B; int ord; bool operator <(const People2& a)const{ return A<a.A||(A==a.A&&B<a.B); } People2(){ A=B=0; ord=0; } People2(int A_,int B_,int ord_){ A=A_; B=B_; ord=ord_; } }; struct Node{ int ls,rs; int w; set<People2> q; }; Node tree[400005]; set<People>::iterator p; char what[200005]; int a[200005],b[200005]; int tot,cnt; int ask[200005]; int n; int zc[200005]; set<People> S[200005]; map<int,int> hash; int root,num; int Query(int root,int l,int r,int A,int B) { if(r<=hash[B]||tree[root].w<A) return -1; if(l==r) return (*(tree[root].q.lower_bound(People2(A,B,1)))).ord; int mid=(l+r)/2; int ans=Query(tree[root].ls,l,mid,A,B); if(ans==-1) ans=Query(tree[root].rs,mid+1,r,A,B); return ans; } void Update(int root,int l,int r,int A,int B,int num,int where) { if(l==r){ tree[root].w=max(tree[root].w,A); tree[root].q.insert(People2(A,B,num)); return; } int mid=(l+r)/2; if(where<=mid) Update(tree[root].ls,l,mid,A,B,num,where); else Update(tree[root].rs,mid+1,r,A,B,num,where); tree[root].w=max(tree[tree[root].ls].w,tree[tree[root].rs].w); } void Readdata() { scanf("%d\n",&n); for(int i=1;i<=n;i++){ scanf("%c",&what[i]); if(what[i]=='D'){ tot++; scanf("%d%d\n",&a[tot],&b[tot]); } else{ cnt++; scanf("%d\n",&ask[cnt]); } } } void First() { for(int i=1;i<=tot;i++) zc[i]=b[i]; sort(zc+1,zc+1+tot); for(int i=1;i<=tot;i++) hash[zc[i]]=i; } void Solve() { tot=cnt=0; for(int i=1;i<=n;i++) if(what[i]=='D'){ tot++; Update(root,1,200000,a[tot],b[tot],tot,hash[b[tot]]); S[hash[b[tot]]].insert(People(a[tot],b[tot],tot)); } else{ cnt++; p=S[hash[b[ask[cnt]]]].lower_bound(People(a[ask[cnt]],b[ask[cnt]],1)); if(++p!=S[hash[b[ask[cnt]]]].end()) printf("%d\n",(*p).ord); else{ int ans=Query(root,1,200000,a[ask[cnt]],b[ask[cnt]]); if(ans==-1) printf("NE\n"); else printf("%d\n",ans); } } } void MakeTree(int& root,int l,int r) { root=++num; if(l==r) return; int mid=(l+r)/2; MakeTree(tree[root].ls,l,mid); MakeTree(tree[root].rs,mid+1,r); } void Close() { fclose(stdin); fclose(stdout); } int main() { Readdata(); MakeTree(root,1,200000); First(); Solve(); Close(); return 0; }
相关文章推荐
- python爬取ajax动态生成的数据 以抓取淘宝评论为例子
- html5 触摸事件
- python中的正则表达式
- Linux内核工程导论——内存管理(二)
- java.net.UnknownHostException: Unable to resolve host "xxx": No address associated with hostname
- Java实现数据结构与算法-链表
- 纯汇编点亮led-以替代uboot的方式执行
- hashset和hashmap的区别
- c与c++ static函数的区别
- ubuntu14.04的 firefox搜索框,一选中,字就没了
- poj 3687 Labeling Balls 【拓扑排序】
- [solr] - solr5.2.1环境搭建 - 使用solr自带的jetty服务器
- 剑指offer 算法 (时间空间效率的平衡)
- 1712: 编程语言 (规律题)
- Appium源码分析(六)-find(上)
- 程序内存分布
- 【C++】单链表的实现
- How can i specify the resource to get from R.res.drawable dynamically?
- UVA699落叶,二叉树递归左右偏移
- SQL Join —— 左联接、右联接、内联接等