本文整理汇总了C++中multiset::lower_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::lower_bound方法的具体用法?C++ multiset::lower_bound怎么用?C++ multiset::lower_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::lower_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scanf
main()
{
int n,m,Q ; scanf("%d%d%d",&m,&n,&Q) ;
s1.insert(0) ; s1.insert(n) ;
s2.insert(0) ; s2.insert(m) ;
d1.insert(n) ; d2.insert(m) ;
while(Q--)
{
char s[6] ; int x ;
scanf("%s%d",s,&x) ;
if(s[0]=='H')
{
auto it=s1.lower_bound(x) ;
int x2=*it ; it-- ; int x1=*it ;
d1.erase(d1.find(x2-x1)) ;
d1.insert(x2-x) ;
d1.insert(x-x1) ;
s1.insert(x) ;
}
else
{
auto it=s2.lower_bound(x) ;
int x2=*it ; it-- ; int x1=*it ;
d2.erase(d2.find(x2-x1)) ;
d2.insert(x2-x) ;
d2.insert(x-x1) ;
s2.insert(x) ;
}
printf("%I64d\n",(LL)(*d1.begin())*(*d2.begin())) ;
}
}
示例2: main
int main() {
int idx, x;
while(~scanf("%d%d", &n, &m)) {
se.clear();
se2.clear();
mn = INF;
for(int i=1; i<=n; i++) {
scanf("%d", a+i);
se.insert(a[i]);
b[i] = a[i];
}
for(int i=2; i<=n; i++)
se2.insert(myabs(a[i]-a[i-1]));
for(multiset<int>::iterator it = se.begin(); ; ) {
multiset<int>::iterator it2 = it;
it++;
if(it == se.end())
break;
mn = min(mn, myabs((*it) - (*it2)));
}
//show_se();
//cout << "Min: " << mn << endl;
while(m--) {
scanf("%s", com);
if(com[0] == 'I') {
scanf("%d%d", &idx, &x);
multiset<int>::iterator it = se.lower_bound(x);
mn = min(mn, myabs((*it) - x));
if(it!=se.begin()) {
it--;
mn = min(mn, myabs(x - (*it)));
}
se.insert(x);
if(idx!=n) {
it = se2.lower_bound(myabs(b[idx] - a[idx+1]));
//se2.erase(myabs(b[i] - a[i+1]));
se2.erase(it);
se2.insert(myabs(x - a[idx+1]));
}
se2.insert(myabs(b[idx] - x));
b[idx] = x;
//show_se();
} else if(com[1] == 'i') {
printf("%d\n", mn);
} else {
multiset<int>::iterator it = se2.end();
it--;
printf("%d\b", *it);
}
}
}
return 0;
}
示例3: main
int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
scanf("%d",&n);
int maxScore=0,minScore=2*n;
For(i,n)scanf("%d",&a[i]);
For(i,n)scanf("%d",&b[i]);
sort(b+1,b+n+1);
For(i,n)st.insert(a[i]);
for(int i=n; i; i--){
it=st.upper_bound(b[i]);
if(it!=st.end()){
maxScore+=2;
st.erase(it);
mark[i]=1;
}
}
For(i,n)if(!mark[i]){
it=st.lower_bound(b[i]);
if(it!=st.end()){
maxScore++;
st.erase(it);
}
}
st.clear();
memset(mark,0,sizeof(mark));
sort(a+1,a+n+1);
For(i,n)st.insert(b[i]);
for(int i=n; i; i--){
it=st.upper_bound(a[i]);
if(it!=st.end()){
minScore-=2;
st.erase(it);
mark[i]=1;
}
}
For(i,n)if(!mark[i]){
it=st.lower_bound(a[i]);
if(it!=st.end()){
minScore--;
st.erase(it);
}
}
printf("%d %d\n",maxScore,minScore);
return 0;
}
示例4: solve
void solve() {
int rez = 0;
multiset <int> :: iterator it;
for (int i = 1; i <= n; ++i) {
it = s.lower_bound(v[i].first);
if (it != s.end() && *it == v[i].first) {
s.erase(it);
s.insert(v[i].second);
++rez;
} else {
if (it == s.begin())
continue;
--it;
s.erase(it);
s.insert(v[i].second);
++rez;
}
}
printf("%d\n", rez);
}
示例5: main
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=0;i<n;i++){
int h,w;
scanf("%d%d",&h,&w);
v[i].get(h,w,0);
}
for(int i=0;i<n;i++){
int h,w;
scanf("%d%d",&h,&w);
v[i+n].get(h,w,1);
}
sort(v,v+2*n,cmp);
m.clear();
int ans=0;
for(int i=0;i<2*n;i++){
// cout<<v[i].id<<" "<<v[i].h<<" "<<v[i].w<<endl;
if(v[i].id==0) m.insert(v[i].w);
else{
it=m.lower_bound(v[i].w);
if(it!=m.end()){
m.erase(it);
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}
示例6: main
int main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#endif
scanf("%d%d", &n, &k);
i64 s = 0;
forn(i, n) scanf("%d", &b[i]), s += b[i];
forn(i, n) scanf("%d", &a[i]);
sort(a, a+n);
f.insert(b, b+n);
ford(i, n) {
auto it = f.lower_bound(a[i]);
if (it == f.end()) {
if (k == 0) {
printf("NIE\n");
return 0;
}
add += a[i];
--k;
a[i] = 0;
} else {
a[i] = *it - a[i];
f.erase(it);
}
}
示例7: main
int main(int argc, char const *argv[])
{
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%I64d", A + i);
s += A[i];
ps[i + 1] = ps[i] + A[i];
}
sum.insert(s);
qu.insert(Pii(n, 0));
for (int i = 0, p; i < n; ++i) {
scanf("%d", &p); --p;
auto it = qu.upper_bound(Pii(p, 0));
// cout << it->second << " " << it->first << endl;
ll tmp = ps[it->first] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.erase(sum.lower_bound(tmp));
tmp = ps[p] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(p, it->second));
tmp = ps[it->first] - ps[p + 1];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(it->first, p + 1));
qu.erase(it);
printf("%I64d\n", *sum.rbegin());
}
return 0;
}
示例8: main
int main() {
scanf( "%d %d", &C, &G );
for ( i = 0; i < C + G; i++ ) {
scanf( "%d %d", &j, &k );
ls.push_back( make_pair( k, ( i < C ) ? -j : j ) );
}
sort( ls.rbegin(), ls.rend() );
for ( i = 0; i < C + G; i++ )
if ( ls[i].second > 0 )
S.insert( ls[i].second );
else { /* It's a cow */
set< int >::iterator it = S.lower_bound( -ls[i].second );
if ( it != S.end() ) {
sol += *it;
S.erase( it );
} else {
sol = -1;
break;
}
}
printf( "%lld\n", sol );
return 0;
}
示例9: main
int main()
{
int T;
scanf("%d",&T);
for(int kase=1; kase<=T; kase++)
{
st.clear();
int n;
scanf("%d",&n);
printf("Case #%d:\n",kase);
while(n--)
{
P t;
scanf("%d%d",&t.x,&t.y);
it=st.lower_bound(t);
if(it==st.begin()||(--it)->y>t.y)
{
//printf("OK");
st.insert(t);
it=st.upper_bound(t);
while(it!=st.end()&&it->y>=t.y)
{
//printf("%d %d\n",it->x,it->y);
st.erase(it++);
}
}
printf("%d\n",st.size());
}
if(kase!=T)
printf("\n");
}
return 0;
}
示例10: main
int main()
{
int n,d,r;
while(scanf("%d%d%d",&n,&d,&r)!=EOF&&n||d||r)
{
int k;
for(int i=1;i<=n;i++)
{
scanf("%d",&k);
s1.insert(k);
}
for(int i=1;i<=n;i++)
{
scanf("%d",&k);
s2.insert(k);
}
int ans=0;
for(int i=1;i<=n;i++)
{
int num=*s1.begin();
int index=d-num;
__typeof(s2.begin()) it=s2.lower_bound(index);
if(it==s2.end())it--;
ans+=r*max(0,num+*it-d);
s1.erase(s1.begin());
s2.erase(it);
}
printf("%d\n",ans);
}
return 0;
}
示例11: main
int main() {
int n, m, p, b; scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d%lld", &A[i].x, &A[i].t);
++A[i].t;
A[i].idx = i;
}
sort(A, A + n, [&] (Frog A, Frog B) {return A.x > B.x;});
for (int i = 0; i < n; ++i) root -> set(A[i].x, min(A[i].x + A[i].t, (LL)INF), i);
while (m--) {
scanf("%d%d", &p, &b);
int frog = root -> at(p);
if (frog == -1) mos.insert({p, b});
else {
A[frog].t += b;
++A[frog].mos_count;
auto it = mos.lower_bound({A[frog].x, 0});
while (it != mos.end() and it -> first < A[frog].x + A[frog].t) {
A[frog].t += it-> second;
++A[frog].mos_count;
mos.erase(it);
it = mos.upper_bound({A[frog].x, 0});
}
root -> set(A[frog].x, min(A[frog].x + A[frog].t,(LL) INF), frog);
}
}
sort(A, A + n, [&] (Frog A, Frog B) {return A.idx < B.idx;});
for (int i = 0; i < n; ++i) printf("%d %lld\n", A[i].mos_count, A[i].t - 1);
}
示例12: solve
void solve(int idx)
{
if(flag)
puts("");
flag=1;
scanf("%d",&N);
printf("Case #%d:\n", idx);
Ms.clear();
while(N--)
{
int L,R;
scanf("%d %d",&L,&R);
Point tmp;
tmp.L=L;tmp.R=R;
it=Ms.lower_bound(tmp);
if(it==Ms.begin()||(--it)->R>R)
{
Ms.insert(tmp);
it=Ms.upper_bound(tmp);
while(it!=Ms.end()&&it->R>=tmp.R)
{
Ms.erase(it++);
}
}
printf("%d\n",Ms.size());
}
}
示例13: main
int main() {
#ifndef ONLINE_JUDGE
freopen("528a.in", "r", stdin);
freopen("528a.out", "w", stdout);
#endif
cin >> w >> h >> n;
rx.insert(0);
rx.insert(w);
ry.insert(0);
ry.insert(h);
distx.insert(-w);
disty.insert(-h);
for(int i = 1 ; i <= n ; ++ i) {
char op; int x;
cin >> op >> x;
if(op == 'V') {
auto p1 = rx.lower_bound(x);
auto p2 = rx.lower_bound(x);
if(p1 != rx.begin())
-- p1;
// cout << "x \n";
// cout << *p1 << ' ' << *p2 << '\n';
rx.insert(x);
distx.erase(distx.find(-(*p2 - *p1)));
distx.insert(-(x - *p1));
distx.insert(-(*p2 - x));
cout << 1LL * (*distx.begin()) * (*disty.begin()) << '\n';
}
else {
auto p1 = ry.lower_bound(x);
auto p2 = ry.lower_bound(x);
if(p1 != ry.begin())
-- p1;
// cout << "y \n";
// cout << *p1 << ' ' << *p2 << '\n';
ry.insert(x);
disty.erase(disty.find(-(*p2 - *p1)));
disty.insert(-(x - *p1));
disty.insert(-(*p2 - x));
cout << 1LL * (*distx.begin()) * (*disty.begin()) << '\n';
}
}
}
示例14: main
int main()
{
//freopen("I.in","r",stdin);
//freopen("I.out","w",stdout);
int T;
scanf("%d", &T);
for(int cas=1;cas<=T;cas++)
{
mst.clear();
int n, m, k, cnt = 0;
long long num;
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < n; ++i)
{
scanf("%lld", &num);
if(num <= k)
{
mst.insert(num);
}
}
while(true)
{
int sz = mst.size();
if(sz < 2)
break;
it1 = mst.end();
it1--;
long long fst = *it1;
mst.erase(it1);
it2 = mst.lower_bound(min(fst, k - fst));
if(it2 == mst.end())
it2--;
if(it2 == mst.begin() && *it2 > (k - fst))
continue;
if(*it2 <= k - fst)
{
ans[cnt++] = fst * ( *it2);
mst.erase(it2);
}
else
{
it2 --;
ans[cnt++] = fst * (*it2);
mst.erase(it2);
}
}
sort(ans, ans + cnt, cmp);
long long res = 0;
for(int i = 0; i < min(m, cnt); ++i)
{
res += ans[i];
}
printf("CASE #%d: %lld\n",cas,res);
}
return 0;
}
示例15: modify
inline void modify(int u) {
col[u] ^= true;
sum += col[u] ? -1 : 1;
while(u) {
d[u] = getD(u);
if(!col[u]) d[u] = make_pair(max(0, d[u].first), max(0, d[u].second));
int val = tree[root[pathR[u]]].opt;ans.erase(ans.lower_bound(-val));
modify(root[pathR[u]], pos[pathR[u]], pos[pathR[u]]+csz[pathR[u]]-1, u);
adjust(pathR[u]), ans.insert(-tree[root[pathR[u]]].opt), u = fa[pathR[u]];
}
}