7 条题解

  • 1
    @ 2025-3-7 0:55:15
    #include<bits/stdc++.h>  // 包含标准库头文件
    
    using namespace std;    // 使用标准命名空间
    
    int main(){
        set<int>se;
        int n,m,t;
        cin>>n>>m;
        for(int i=0;i<n;i++){
    		cin>>t;
    		se.insert(t);
    	}
    	int c,num;
    	while(m--){
    		cin>>c>>num;
    		if(c==1){
    			auto j = se.find(num);
    			if(j!=se.end()) cout<<*j<<endl;
    			else cout<<"NO"<<endl;
    		}else if(c==2){
    				auto x = se.begin();
    				if(num<=*x) cout<<"NO"<<endl;
    				else{
    					auto j = se.lower_bound(num);
    					j--;
    					cout<<*j<<endl;
    				}
    		}else if(c==3){
    			auto x = se.end();
    			x--;
    			if(num>=*x) cout<<"NO"<<endl;
    			else{
    				auto j = se.upper_bound(num);
    				cout<<*j<<endl;
    			}
    		}		
    	}
    }
    

    信息

    ID
    70
    时间
    2000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    371
    已通过
    123
    上传者