标签:insert hdu 插入 Tunnel bound st STL int include
看完题的第一眼就在怀疑tag
能二分的事为什么要写线段树
普通二分没法支持动态插入
用c++自带的stl
set<int>st;
st.clear()清空
st.insert(x)插入
r返回第一个>=x的数.upper_bound()为第一个>x的数
l返回第一个<x的数,只要用r指向的位置-1即可
在有序数组中插入一个数,必然只能位于两个数之间
r=*st.lower_bound(x); l=*(--st.lower_bound(x));
--
#include <iostream> #include <math.h> #include <string.h> #include <vector> #include <map> #include <queue> #include <stdio.h> #include <algorithm> #include <cstdio> #include <set> using namespace std; int d[500000],cnt=0; set<int>st; int main( ) { int n,m; //freopen("lys.in","r",stdin); while(cin>>n>>m) { cnt=0; int x; st.clear(); st.insert(0); st.insert(n+1); for(int i=1;i<=m;i++) { char type[2]; scanf("%s",type); if(type[0]=='R') { st.erase(d[cnt]); cnt--; } else if(type[0]=='D') { scanf("%d",&x); st.insert(x); cnt++; d[cnt]=x; } else { int l,r; scanf("%d",&x); if(st.count(x)) { printf("0\n");continue; } r=*st.lower_bound(x); l=*(--st.lower_bound(x)); // cout<<l<<" "<<r<<endl; printf("%d\n",r-l-1); } } } }
标签:insert,hdu,插入,Tunnel,bound,st,STL,int,include 来源: https://www.cnblogs.com/liyishui2003/p/15484422.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。