0pts P5076
查看原帖
0pts P5076
1328264
wjy7777楼主2025/6/14 11:41

只对subtask1

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=2147483647;
set<int> s;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int t,n,p;
	cin>>n;
	for (int i=0; i<n; i++) {
		cin>>t>>p;
		if (t==5) {
			s.insert(p);
		} else if (t==1) {
			int ans=0;
			for (set<int>::iterator it=s.begin(); it!=s.end(); it++) {
				ans++;
				if (*it==p) {
					cout<<ans<<endl;
					break;
				}
			}
		} else if (t==2) {
			int ans=0;
			for (set<int>::iterator it=s.begin(); it!=s.end(); it++) {
				ans++;
				if (ans==p) {
					cout<<*it<<endl;
					break;
				}
			}
		}
		else if (t==3){
			for (set<int>::iterator it=s.begin(); it!=s.end(); it++) {
				if (*it==p) {
					if (it!=s.begin()){
						it--;
						cout<<*it<<endl;
					}
					else{
						cout<<-inf<<endl;
					}
					break;
				}
			}
		}
		else if (t==4){
			for (set<int>::iterator it=s.begin(); it!=s.end(); it++) {
				if (*it==p) {
					if (it!=s.begin()){
						it++;
						cout<<*it<<endl;
					}
					else{
						cout<<inf<<endl;
					}
					break;
				}
			}
		}
	}
	return 0;
}
2025/6/14 11:41
加载中...