Subtask#0全WA,用的set
查看原帖
Subtask#0全WA,用的set
1137152
SmartCirno楼主2024/8/30 04:33

题目数据保证插入前 xx 不在集合中,所以用 setset 没问题,但是只过了 HACK ,自己构造的数据也全部AC,求调。

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
#define INF 2147483647
set<int> st;
int q;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int op,x;
		cin>>op>>x;
		if(op==1)
		{
			if(x<(*st.begin()))cout<<1<<endl;
			else
			{
				auto it=st.find(x);
				cout<<distance(st.begin(),it)+1<<endl;
			}
		}
		else if(op==2)
		{
			for(int val:st)
			{
				if(x--==1)
				{
					cout<<val<<endl;
					break;
				}
			}
		}
		else if(op==3)
		{
			auto it=st.lower_bound(x);
			if(it==st.begin())cout<<-INF<<endl;
			else cout<<*(--it)<<endl;
			
		}
		else if(op==4)
		{
			auto it=st.upper_bound(x);
			if(it==st.end())cout<<INF<<endl;
			else cout<<*it<<endl;
		}
		else
		{
			st.insert(x);
		}
	}
	return 0;
}

2024/8/30 04:33
加载中...