关于std::multiset
查看原帖
关于std::multiset
709447
tx774楼主2022/11/16 22:30

为啥以下代码把ddq a=cpp q.find(x)换成q.lower_bound(x)就AC了呢? 在这题中这两个不是相等德玛

#include<bits/stdc++.h>
using namespace std;
typedef multiset<int>::iterator ddq;
multiset<int> q;
int Q;
int main()
{
	q.insert(2147483647);
	q.insert(-2147483647);
	cin>>Q;
	while(Q--)
	{
		int op,x;
		cin>>op>>x;
		if(op==1)
		{
			ddq a=q.find(x);//这里
			int ans=0;
			for(ddq b=q.begin();b!=a;++b)
				ans++;
			cout<<ans<<endl;
		}
		else if(op==2)
		{
			int num=1;
			ddq a;
			for(a=q.begin();num<=x;++a)
				num++;
			cout<<*a<<endl;
		}
		else if(op==3)
		{
			ddq a=q.lower_bound(x);
			a--;
			cout<<*a<<endl;
		}
		else if(op==4)
		{
			ddq a=q.upper_bound(x);
			cout<<*a<<endl;
		}
		else if(op==5)
		{
			q.insert(x);
		}
	}
	return 0;
}
2022/11/16 22:30
加载中...