本文整理汇总了C++中multiset::upper_bound方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::upper_bound方法的具体用法?C++ multiset::upper_bound怎么用?C++ multiset::upper_bound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::upper_bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: main
int main()
{
scanf("%d", &t);
while(t--)
{
y.clear();
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d%d", &a[i].h, &a[i].w);
sort(a, a + n);
for(int i = 0; i < n; ++i)
scanf("%d%d", &b[i].h, &b[i].w);
sort(b, b + n);
ans = 0;
for(int i = 0, j = 0; i < n; ++i)
{
while(j < n && b[j].h <= a[i].h)
y.insert(b[j++].w);
if(y.empty())
continue;
multiset<int>::iterator it = y.upper_bound(a[i].w);
if(it != y.begin())
{
y.erase(--it);
++ans;
}
}
printf("%d\n", ans);
}
return 0;
}
示例3: main
int main(){
int T, n;
scanf("%d", &T);
while( T-- ){
scanf("%d", &n);
for(int i=0 ; i < n ; ++i)
scanf("%d%d", &a[i].h, &a[i].w);
for(int i=0 ; i < n ; ++i)
scanf("%d%d", &b[i].h, &b[i].w);
sort( a, a+n, cmp );
sort( b, b+n, cmp );
st.clear();
int ans = 0;
for(int i=0,j=0 ; i < n ; ++i){
while( j < n && a[i].h >= b[j].h ){
st.insert(b[j].w);
j++;
}
it = st.upper_bound(a[i].w);
if( it != st.begin() && !st.empty() ){
--it;
st.erase(it);
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}
示例4: main
int main () {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d %d", x+i, y+i);
p[i] = i;
}
int res = 0;
sort(p, p+n, cmp_t);
for (int i = 0; i < k; i++)
s.insert(0);
for (int i = 0; i < n; i++) {
it = s.upper_bound(x[p[i]]);
if (it == s.begin())
continue;
--it;
res++;
s.erase(it);
s.insert(y[p[i]]);
}
printf("%d\n", res);
}
示例5: 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());
}
}
示例6: scanf
main()
{
int i,j,n,t,C;
multiset<data>::iterator now,last;
scanf("%d",&t);
for(C=1;C<=t;C++)
{
scanf("%d",&n);
s.clear();
s.insert((data){-1,1000000001});
s.insert((data){1000000001,-1});
if(C>1)puts("");
printf("Case #%d:\n",C);
while(n--)
{
scanf("%d %d",&i,&j);
while(1)
{
last=s.upper_bound((data){i,j});
if(j>(now=last--)->b)
break;
s.erase(*now);
}
if(j<last->b ||(i==last->a && j==last->b))
s.insert((data){i,j});
printf("%d\n",s.size()-2);
}
}
}
示例7: main
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while(t--){
S.clear();
cin >> n;
for(int i=0;i<n;i++){
cin >> x;
it = S.upper_bound(x);
if(it==S.end()){
S.insert(x);
}
else{
S.erase(it);
S.insert(x);
//(*it) = x;
}
}
cout << S.size() << " ";
for(multiset<int>::iterator it=S.begin();it!=S.end();it++){
cout << (*it) << " ";
}
cout << endl;
}
return 0;
}
示例8: 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;
}
示例9: main
int main(){
int n, m, x;
while( scanf("%d%d", &n, &m) != EOF ){
st.clear();
for(int i=0 ; i < n ; ++i){
scanf("%d", &x);
st.insert(x);
}
for(int i=0 ; i < m ; ++i)
scanf("%d", &a[i].d);
for(int i=0 ; i < m ; ++i)
scanf("%d", &a[i].p);
if( m < n ){
puts("No"); continue;
}
sort( a, a+m, cmp );
LL ans = 0;
for(int i=0 ; i < m ; ++i){
it = st.upper_bound( a[i].d );
if( it != st.begin() ){
it--;
st.erase(it);
ans += a[i].p;
if( st.empty() ) break;
}
}
if( st.empty() ) printf("%I64d\n", ans);
else puts("No");
}
return 0;
}
示例10: 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);
}
示例11: main
int main(){
int n;rit(n);
for(int l,r;n;--n){
rit(l,r);
auto it=st.upper_bound(r);
if(it!=st.end())st.erase(it);
st.insert(l);
}
printf("%d\n",st.size());
}
示例12: main
int main(){
int n;cin>>n;
while(n--){
int l,r;cin>>l>>r;
auto it=st.upper_bound(r);
if(it!=st.end())st.erase(it);
st.insert(l);
}
cout<<st.size()<<endl;
return 0;
}
示例13: check
bool check()
{
if(tcnt < st.size()) return 0 ;
scnt=0 ;
for(int i=0;!st.empty() && i<tcnt;i++)
{
auto it=st.upper_bound(tmp[i]) ;
if(it!=st.begin())
it-- , st_tmp[scnt++]=*it , st.erase(it) ;
}
int sz=st.size() ;
for(int i=0;i<scnt;i++) st.insert(st_tmp[i]) ;
return sz==0 ;
}
示例14: main
int main()
{
while (1)
{
int n;
scanf("%d",&n);
if (n==0)
break;
for (int i=1;i<=n;i++)
scanf("%d%d",&a[i].capacity,&a[i].time);
int m;
scanf("%d",&m);
for (int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d:%d",&b[i].capacity,&x,&y);
b[i].time=(x-14)*60+y;
}
m++;
b[m].capacity=0;
b[m].time=1<<30;
sort(a+1,a+n+1,cmp);
sort(b+1,b+m+1,cmp);
int now=1;
s.clear();
for (int i=1;i<=m;i++)
{
while (now<=n && a[now].time<=b[i].time)
s.insert(a[now++]);
set <state>::iterator k=s.upper_bound(b[i]);
if (k==s.begin())
continue;
s.erase(--k);
}
int sum=0;
for (set <state>::iterator k=s.begin();k!=s.end();k++)
sum+=k->capacity;
static int id=0;
printf("Trial %d: %d %d\n\n",++id,s.size(),sum);
}
return(0);
}
示例15: dfs
void dfs(int root) {
if(k / a[root] > 1e9) {
re += st.size();
} else {
// cout << "size=" << st.size() << endl;
multiset<int>::iterator it = st.upper_bound( (int)(k / a[root]) );
if(it == st.end()) {
re += st.size();
} else {
re += sp.rank( *it );
}
}
st.insert( a[root] );
sp.insert( a[root] );
for(int i = 0; i < mp[root].size(); ++i) {
dfs( mp[root][i] );
}
sp.del( a[root] );
st.erase( st.find(a[root] ) );
}