本文整理汇总了C++中set::lower_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ set::lower_bound方法的具体用法?C++ set::lower_bound怎么用?C++ set::lower_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::lower_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: queryRange
bool queryRange(int left, int right) {
auto it = rc.lower_bound(make_pair(left, right));
return it!=rc.end() && it->first <= left && it->second >= right;
}
示例2: main
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for (int i = 1; i <= n; ++i)
{
cir[i].read();
son[i].clear();
}
son[0].clear();
sort(cir+1,cir+n+1);
e.clear();
for( int i = 1; i <= n; ++i)
{
e.push_back(make_pair(cir[i].left,i));
e.push_back(make_pair(cir[i].x + cir[i].r, -i));
}
sort(e.begin(),e.end());
s.clear();
for (int i = 0; i < e.size(); ++i)
{
cur = e[i].first;
if (e[i].second > 0){
int id = e[i].second;
set<circmp>::iterator t = s.lower_bound(circmp(id));
if(t == s.end())
{
fa[id] = 0;
//son[0].push_back(id);
}else{
int nid = (*t).id;
if (cir[nid].contain(cir[id])){
fa[id] = nid;
// son[id].clear();
son[nid].push_back(id);
}else{
fa[id] = fa[nid];
// son[id].clear();
son[fa[id]].push_back(id);
}
}
s.insert(circmp(id));
s.insert(circmp(-id));
}else{
int id = -e[i].second;
s.erase(circmp(id));
s.erase(circmp(-id));
}
}
// memset(maxx,-1,sizeof(maxx));
// dfs(0);
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (fa[i] == 0) {
ans ^= sg(i);
}
}
puts(ans ? "Alice" : "Bob");
}
return 0;
}
示例3: track
//.........这里部分代码省略.........
pos.y = ( itNext->y - it->y ) / ( (double)( itNext->t - it->t ) * 1.0e-6 ) * ( (double)commonParam.intervalTrajectory * 1.0e-6 ) + it->y;
pos.t = it->t + commonParam.intervalTrajectory;
it = itTrj->insert( it, pos );
}
++it;
++itNext;
}
}
// 結果の保存
p_result->clear();
resultTrajectory.clear();
vector<int>::iterator itID = idOpt.begin();
for( vector<TrajectoryElement>::iterator itTrj = opt.begin(); itTrj != opt.end(); ++itTrj, ++itID ) {
int id = ( *itID == -1 ) ? idNext++ : *itID;
CTrajectory trj;
trj.push_back( *itTrj );
resultTrajectory[ id ] = trj; // resultTrajectory$B$O<[email protected]$K$b;H$&$N$G>/$7D9$$(B
//trj.Clip( 0, timeTracking - ( commonParam.termTracking - commonParam.intervalTracking ) );
//(*p_result)[ id ] = trj; // $BI=<(MQ(B
}
//map<unsigned long long, multimap<int,Point2d> > ext_result;
unsigned long long time;
p_ext_result->insert( remainedExtendedResult.begin(), remainedExtendedResult.end() );
for( /*unsigned long long*/ time = max( timeTracking - commonParam.termTracking, timeEarliestPEPMap )
; time < timeTracking - ( commonParam.termTracking - commonParam.intervalTracking )
; time += commonParam.intervalTrajectory ) {
(*p_result)[ time ];
(*p_ext_result)[ time ];
const set<TIME_MICRO_SEC>::iterator it_start_pepmap_time = time_of_received_pepmap.lower_bound( time );
const set<TIME_MICRO_SEC>::iterator it_end_pepmap_time = time_of_received_pepmap.lower_bound( time + commonParam.intervalTrajectory );
for( set<TIME_MICRO_SEC>::iterator it = it_start_pepmap_time; it != it_end_pepmap_time; ++it ) {
(*p_ext_result)[ *it ];
}
map<int,CTrajectory>::const_iterator itResult = resultTrajectory.begin();
for( ; itResult != resultTrajectory.end(); ++itResult ) {
const CTrajectory& trajectory = itResult->second;
if( trajectory.size() > 0 ) {
TrajectoryElement::iterator itPos = trajectory.front().begin();
for( ; itPos != trajectory.front().end(); ++itPos ) {
if( itPos->t == time ) {
(*p_result)[ time ][ itResult->first ] = Point2d( itPos->x, itPos->y );
const int trj_no = itPos->ID;
if( trj_no < trajectoriesClustered.size() ) {
for( CTrajectory::iterator it = trajectoriesClustered[ trj_no ].begin()
; it != trajectoriesClustered[ trj_no ].end(); ++it ) {
TrajectoryElement::iterator itPos2;
if( ( itPos2 = it->find( PosXYT( 0.0, 0.0, time ) ) ) != it->end() ) {
(*p_ext_result)[ time ].insert( pair<int,Point2d>( itResult->first, Point2d( itPos2->x, itPos2->y ) ) );
PosXYT pos0, pos1;
pos0 = *itPos2;
advance( itPos2, 1 );
if( itPos2 != it->end() ) {
pos1 = *itPos2;
for( set<TIME_MICRO_SEC>::iterator it = it_start_pepmap_time; it != it_end_pepmap_time; ++it ) {
PosXYT pos;
pos.x = ( pos1.x - pos0.x ) / ( (double)( pos1.t - pos0.t ) ) * ( (double)( *it - *it_start_pepmap_time ) ) + pos0.x;
pos.y = ( pos1.y - pos0.y ) / ( (double)( pos1.t - pos0.t ) ) * ( (double)( *it - *it_start_pepmap_time ) ) + pos0.y;
(*p_ext_result)[ *it ].insert( pair<int,Point2d>( itResult->first, Point2d( pos.x, pos.y ) ) );
}
示例4: pred
int pred( int x ) {
set<int>::iterator it = S.lower_bound( x );
--it;
return *it;
}
示例5: main
int main()
{
freopen("ti.in","r",stdin);
scanf("%d",&zu);
for (zz=1;zz<=zu;zz++)
{
memset(f,0,sizeof(f));
mm=0;
shu[0]=0;
s.clear();
// cout<<s.size()<<endl;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&shu[i]);
mm=max(mm,shu[i]);
}
tt.p=0;
tt.d=0;
s.insert(tt);
mm=1;
for (i=1;i<=n;i++)
{
if (shu[i-1]<shu[i])
{
f[i][0]=f[i-1][0]+1;
f[i][1]=f[i-1][1]+1;
}
else
{
f[i][0]=1;
f[i][1]=1;
}
mm=max(mm,f[i][0]);
tt.p=shu[i];
tt.d=f[i][0];
// cout<<s.size()<<endl;
set<D>::iterator it;
if (s.size()!=1)
{
it=s.lower_bound(tt);
it--;
}
else
it=s.begin();
//if (((*it).p==tt.p)&&(it!=s.begin()))
// it--;
f[i][1]=max(f[i][1],(*it).d+1);
mm=max(mm,f[i][1]);
if (s.size()!=1)
{
it=s.lower_bound(tt);
it--;
}
else
it=s.begin();
//if (it==s.end())
// it--; //非常重要!
if ((*it).p==shu[i])
{
if ((*it).d<f[i][0])
{
s.erase(it);
s.insert(tt);
}
}
else
{
if (f[i][0]>(*it).d)
{
it=(s.insert(tt)).first;
it++;
for (;it!=s.end();)
{
if ((*it).d<f[i][0])
s.erase(it++);
else
break;
}
}
}
}
cout<<mm<<endl;
}
return 0;
}
示例6: main
int main( int argc, char* argv[] ){
ios::sync_with_stdio( false );
int Q, x, i, j;
cin >> N >> Q;
h.insert( segt( 1, N ) );
while( Q-- ){
cin >> x;
if( x ){
if( put[x] ){
int pos = put[x];
TI( used ) itnxt, itprv;
itnxt = used.upper_bound( pos );
itprv = used.lower_bound( pos );
int nxt, prv;
nxt = prv = -1;
if( itprv != used.begin() ){
itprv--;
prv = *itprv;
} else {
prv = 0;
}
if( itnxt != used.end() ){
nxt = *itnxt;
} else {
nxt = N+1;
}
used.erase( pos );
put.erase( x );
down( pos );
int from, to;
from = to = pos;
if( nxt != pos+1 ){
h.erase( segt( pos+1, nxt-1 ) );
to = nxt-1;
}
if( prv+1 != pos ){
h.erase( segt(prv+1, pos-1) );
from = prv+1;
}
h.insert( segt( from, to ) );
} else {
segt fre = *(h.begin());
h.erase( h.begin() );
int pos = fre.first + (fre.second-fre.first+1)/2;
put[x] = pos;
used.insert( pos );
up( pos );
if( pos-1 >= fre.first ) h.insert( segt( fre.first, pos-1 ) );
if( pos+1 <= fre.second ) h.insert( segt( pos+1, fre.second ) );
}
} else {
cin >> i >> j;
cout << get(j) - get(i-1) << "\n";
}
}
return 0;
}
示例7: get
int get(int gain){//minimo costo de obtener tal ganancia
set<V>::iterator p=s.lower_bound((V){gain, 0});
return p==s.end()? INF : p->cost;}
示例8: main
int main()
{
for(int i=0;i<10;i++) n[i].clear();
n[1].insert(1);
n[1].insert(2);
n[1].insert(3);
n[1].insert(4);
n[1].insert(5);
n[1].insert(6);
n[1].insert(7);
n[1].insert(8);
n[1].insert(9);
n[1].insert(0);
n[2].insert(2);
n[2].insert(3);
n[2].insert(5);
n[2].insert(6);
n[2].insert(8);
n[2].insert(9);
n[2].insert(0);
n[3].insert(3);
n[3].insert(6);
n[3].insert(9);
n[4].insert(4);
n[4].insert(5);
n[4].insert(6);
n[4].insert(7);
n[4].insert(8);
n[4].insert(9);
n[4].insert(0);
n[5].insert(5);
n[5].insert(6);
n[5].insert(8);
n[5].insert(9);
n[5].insert(0);
n[6].insert(6);
n[6].insert(9);
n[7].insert(7);
n[7].insert(8);
n[7].insert(9);
n[7].insert(0);
n[8].insert(8);
n[8].insert(9);
n[8].insert(0);
n[9].insert(9);
n[0].insert(0);
s.clear();
rs.clear();
for(int i=0;i<=999;i++)
if(judge(i))
{
s.insert(i);
rs.insert(i);
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
int nxt = *(s.lower_bound(x));
int pre = *(rs.lower_bound(x));
if(nxt - x > x - pre)
printf("%d\n" , pre);
else
printf("%d\n" , nxt);
}
return 0;
}
示例9: main
int main() {
int que;
scanf("%d", &que);
for (int i = 0; i < que; i++) {
scanf("%d %d %d", t+i, &p[i].x, &p[i].y);
if (t[i]) {
scanf("%d %d", &q[i].x, &q[i].y);
}
else {
vp.push_back(make_pair(p[i], i));
}
}
sort(vp.begin(), vp.end());
for (int i = 0; i < vp.size(); i++)
id[vp[i].second] = i+1;
fen bup(vp.size() + 2), blow(vp.size()+ 2);
for (int i = 0; i < que; i++) {
if (t[i] == 0) {
pair<point, int> now = make_pair(p[i], id[i]);
lower.insert(now);
set<pair<point, int> >::iterator it = lower.lower_bound(now);
if (baddown(it))
lower.erase(it);
else {
blow.upd(now.second, +1);
set<pair<point, int> >::iterator nx = it;
nx++;
while (nx != lower.end() && baddown(nx)) {
blow.upd(nx->second, -1);
lower.erase(nx++);
}
nx = it;
while (nx != lower.begin()) {
nx--;
if (baddown(nx)) {
blow.upd(nx->second, -1);
lower.erase(nx);
nx = it;
}
else
break;
}
}
// upper
upper.insert(now);
it = upper.lower_bound(now);
if (badup(it))
upper.erase(it);
else {
bup.upd(now.second, +1);
set<pair<point, int> >::iterator nx = it;
nx++;
while (nx != upper.end() && badup(nx)) {
bup.upd(nx->second, -1);
upper.erase(nx++);
}
nx = it;
while (nx != upper.begin()) {
nx--;
if (badup(nx)) {
bup.upd(nx->second, -1);
upper.erase(nx);
nx = it;
}
else
break;
}
}
}
else {
int ans = 1, tot = (int)upper.size() + (int)lower.size() - 4;
set<pair<point, int> >::iterator lowa = lower.lower_bound(make_pair(p[i], -1)), lowb = lower.lower_bound(make_pair(q[i], -1));
set<pair<point, int> >::iterator upa = upper.lower_bound(make_pair(p[i], -1)), upb = upper.lower_bound(make_pair(q[i], -1));
if (lowa != lower.end() && lowb != lower.end() && lowa->first == p[i] && lowb->first == q[i]) {
int d = blow.get(lowb->second) - blow.get(lowa->second);
if (d > 0) {
d--;
ans = (tot-d >= d);
}
else {
d = -d - 1;
ans = (d >= tot-d);
}
}
else if (upa != upper.end() && upb != upper.end() && upa->first == p[i] && upb->first == q[i]) {
int d = bup.get(upb->second) - bup.get(upa->second);
if (d > 0) {
d--;
ans = (d >= tot-d);
}
else {
d = -d - 1;
ans = (tot-d >= d);
}
}
else if (lowa != lower.end() && upb != upper.end() && lowa->first == p[i] && upb->first == q[i]) {
int d = blow.get(lowa->second) + bup.get(upb->second) - 3;
ans = (d >= tot-d);
}
//.........这里部分代码省略.........
示例10: main
int main(){
ios_base::sync_with_stdio(false);
cin >> w >> h >> n;
cuth.insert(0);
cuth.insert(h);
dh.insert(MP(h, 1));
cutv.insert(0);
cutv.insert(w);
dv.insert(MP(w, 1));
while(n--){
char fi;
int se;
cin >> fi >> se;
if(fi == 'H'){
init it1 = cuth.lower_bound(se), it2 = it1;
it1--;
int dis1 = se - (*it1),
dis2 = (*it2) - se;
pit it3 = dh.lower_bound(MP((*it2) - (*it1), 0));
dh.erase(it3);
pie t = *it3;
t.R--;
if(t.R)
dh.insert(t);
it3 = dh.lower_bound(MP(dis1, 0));
if(it3 == dh.end() or it3->L != dis1)
dh.insert(MP(dis1, 1));
else{
t = *it3;
dh.erase(it3);
t.R++;
dh.insert(t);
}
it3 = dh.lower_bound(MP(dis2, 0));
if(it3 == dh.end() or it3->L != dis2)
dh.insert(MP(dis2, 1));
else{
t = *it3;
dh.erase(it3);
t.R++;
dh.insert(t);
}
cuth.insert(se);
}
else{
init it1 = cutv.lower_bound(se), it2 = it1;
it1--;
int dis1 = se - (*it1),
dis2 = (*it2) - se;
pit it3 = dv.lower_bound(MP((*it2) - (*it1), 0));
dv.erase(it3);
pie t = *it3;
t.R--;
if(t.R) dv.insert(t);
it3 = dv.lower_bound(MP(dis1, 0));
if(it3 == dv.end() or it3->L != dis1)
dv.insert(MP(dis1, 1));
else{
t = *it3;
dv.erase(it3);
t.R++;
dv.insert(t);
}
it3 = dv.lower_bound(MP(dis2, 0));
if(it3 == dv.end() or it3->L != dis2)
dv.insert(MP(dis2, 1));
else{
t = *it3;
dv.erase(it3);
t.R++;
dv.insert(t);
}
cutv.insert(se);
}
pit ith = dh.end(), itv = dv.end();
ith--;
itv--;
cout << 1LL * (ith->L) * (itv->L) << endl;
}
return 0;
}
示例11: main
int main(){
freopen("in.txt", "r", stdin);
freopen("outstd.txt", "w", stdout);
int _;
scanf("%d", &_);
while (_--){
scanf("%d", &n);
for (int i = 1; i <= n; ++ i){
scanf("%d", &l[i]);
}
for (int i = 1; i <= n; ++ i){
scanf("%d", &r[i]);
}
for (int i = 1; i <= n; ++ i){
scanf("%d", &c[i]);
}
from.clear();
now.clear();
for (int i = 1; i <= n; ++ i){
dp[i] = -1;
}
from.insert(Node(c[1], 1));
dp[1] = 0;
for (int i = 2; i <= n; ++ i){
now.insert(i);
}
while (!from.empty()){
int k = (*from.begin()).id; from.erase(from.begin());
wait.clear();
set<int>::iterator it = now.lower_bound(l[k] + k);
while (it != now.end()){
int to = (*it);
if (to > r[k] + k) break;
dp[to] = dp[k] + 1ll * c[k];
wait.push_back(to);
++ it;
}
for (int i = 0; i < wait.size(); ++ i){
now.erase(wait[i]);
from.insert(Node(dp[wait[i]] + 1ll * c[wait[i]], wait[i]));
}
wait.clear();
it = now.upper_bound(k - l[k]);
if (it == now.begin()) continue;
do{
-- it;
int to = (*it);
if (to < k - r[k]) break;
dp[to] = dp[k] + 1ll * c[k];
wait.push_back(to);
}while(it != now.begin());
for (int i = 0; i < wait.size(); ++ i){
now.erase(wait[i]);
from.insert(Node(dp[wait[i]] + 1ll * c[wait[i]], wait[i]));
}
}
for (int i = 1; i <= n; ++ i){
printf("%lld%c", dp[i], i == n ? '\n' : ' ');
}
}
return 0;
}
示例12: main
int main()
{
scanf("%d%d%d%d%d%d",&n,&m,&t,&tp,&tu,&td);
int x0,y0,x1,y1,ans=0x7fffffff,val1,val2;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
scanf("%d",&M[i][j]);
if (M[i][j]==M[i][j-1])
L[i][j]=L[i][j-1]+tp,R[i][j]=R[i][j-1]+tp;
else if (M[i][j]<M[i][j-1])
L[i][j]=L[i][j-1]+td,R[i][j]=R[i][j-1]+tu;
else if (M[i][j]>M[i][j-1])
L[i][j]=L[i][j-1]+tu,R[i][j]=R[i][j-1]+td;
//=.= 0.0 -.- ←_← →_→QwQ OAO OvO
if (M[i][j]==M[i-1][j])
U[i][j]=U[i-1][j]+tp,D[i][j]=D[i-1][j]+tp;
else if (M[i][j]<M[i-1][j])
U[i][j]=U[i-1][j]+td,D[i][j]=D[i-1][j]+tu;
else if (M[i][j]>M[i-1][j])
U[i][j]=U[i-1][j]+tu,D[i][j]=D[i-1][j]+td;
}
}
spiii tans;
pair<int,int> last;
for (int i=1;i<=n;i++)
for (int j=i+2;j<=n;j++)
{
for (int k=1;k<=m;k++)
{
if (k>=3)
{
val1=U[j][k]-U[i][k]+L[i][k]+R[j][k];
tans=S.lower_bound(make_pair(t-(U[j][k]-U[i][k]+L[i][k]+R[j][k]),k));
if (tans!=S.end())
{
if (abs(val1+tans->first-t)<abs(ans-t))
{
ans=val1+tans->first;
x0=i,x1=j,y0=tans->second,y1=k;
}
}
if (tans!=S.begin())
{
tans--;
if (abs(val1+tans->first-t)<abs(ans-t))
{
ans=val1+tans->first;
x0=i,x1=j,y0=tans->second,y1=k;
}
}
}
if (k>1)
S.insert(last);
last=make_pair(D[j][k]-D[i][k]-L[i][k]-R[j][k],k);
}
S.clear();
}
printf("%d %d %d %d\n",x0,y0,x1,y1);
/* for (int i=1;i<=n;i++,printf("\n"))
for (int j=1;j<=m;j++)
printf("%d\t",L[i][j]);
printf("\n");
for (int i=1;i<=n;i++,printf("\n"))
for (int j=1;j<=m;j++)
printf("%d\t",R[i][j]);
printf("\n");
for (int i=1;i<=n;i++,printf("\n"))
for (int j=1;j<=m;j++)
printf("%d\t",U[i][j]);
printf("\n");
for (int i=1;i<=n;i++,printf("\n"))
for (int j=1;j<=m;j++)
printf("%d\t",D[i][j]);
int a,b,c,d;
while (~scanf("%d%d%d%d",&a,&b,&c,&d))
{
printf("%d\n",L[a][d]-L[a][b]+U[c][d]-U[a][d]+R[c][d]-R[c][b]+D[c][b]-D[a][b]);
}*/
return 0;
}
示例13: main
int main()
{
scanf("%d %d %d", &d, &n, &m);
for (int i = 0; i < m; ++i)
scanf("%d %d", &a[i].x, &a[i].p);
sort(a, a+m);
segs.insert(pii(0, min(n, d)));
// for (it = segs.begin(); it != segs.end(); ++it)
// printf("[%d %d] ", (*it).F, (*it).S);
// printf("\n");
for (int i = 0; i < m; ++i)
{
it2 = it = segs.lower_bound(pii(a[i].x + 1, -1));
pii p1, p2;
if (it == segs.end())
p1 = pii(d, d);
else
p1 = *it;
--it2;
p2 = *it2;
if (p2.S - a[i].x >= n)
continue;
if (a[i].x > p2.S)
{
if (a[i].x + n < p1.F)
{
res += (ll)n * a[i].p;
segs.insert(pii(a[i].x, a[i].x + n));
}
else
{
res += (ll)(p1.F - a[i].x) * a[i].p;
if (it != segs.end())
segs.erase(it);
segs.insert(pii(a[i].x, p1.S));
}
}
else
{
if (a[i].x + n < p1.F)
{
res += (ll)(a[i].x + n - p2.S) * a[i].p;
segs.erase(it2);
segs.insert(pii(p2.F, a[i].x + n));
}
else
{
res += (ll)(p1.F - p2.S) * a[i].p;
if (it != segs.end())
segs.erase(it);
segs.erase(it2);
segs.insert(pii(p2.F, p1.S));
}
}
// for (it = segs.begin(); it != segs.end(); ++it)
// printf("[%d %d] ", (*it).F, (*it).S);
// printf("\n");
}
if (segs.size() != 1)
res = -1;
else if ((*segs.begin()).second != d)
res = -1;
printf("%lld", res);
return 0;
}
示例14: get
bool get(int x, int y) {
auto it = um.lower_bound(x);
return it == um.end() || *it >= y;
}
示例15: addNum
void addNum(int val)
{
int flag=0;
int a,b;
// 空集特殊处理
if (Set.size()==0)
{
Set.insert(Interval(val,val));
return;
}
// 如果已经存在于已有的区间中,那么什么都不用做
auto it = Set.lower_bound(Interval(val,val));
if (val>=it->start && val<=it->end)
return;
if (it!=Set.begin())
{
it--;
if (val>=it->start && val<=it->end)
return;
}
// 如果可以与一个区间相接,那么更新那个区间
it = Set.lower_bound(Interval(val,val));
if (it!=Set.begin())
{
it--;
if (it->end==val-1)
{
a = it->start;
b = val;
Set.erase(it);
Set.insert(Interval(a,b));
flag=1;
}
}
it = Set.lower_bound(Interval(val,val));
if (it!=Set.end() && it->start==val+1)
{
a = val;
b = it->end;
Set.erase(it);
Set.insert(Interval(a,b));
flag++;
}
// 如果更新了两个区间,说明这两个区间可以拼接起来。
if (flag==2)
{
it = Set.lower_bound(Interval(val,val));
if (it!=Set.begin() && it!=Set.end())
{
auto it0=it;
it0--;
if (it0->end==it->start)
{
a=it0->start;
b=it->end;
Set.erase(it0);
Set.erase(it);
Set.insert(Interval(a,b));
}
}
}
// 没有相邻接的区间可以更新,那么就自己单独作为一个区间
else if (flag==0)
{
Set.insert(Interval(val,val));
}
}