2 条题解

  • 2
    @ 2023-10-22 20:57:12
    #include <bits/stdc++.h>
    using namespace std;
    int vec[1000007];
    int qq[1000007];
    int k;
    //映射
    
    map<int,int > m;
    map<int,int >::iterator it;
    //vector<int >::iterator p;
    int *p;
    int main() {
    	int n, q;
    	//cin >> n>>q;
    	scanf("%d %d", &n, &q);
    	//int temp;
    	for (int i = 0; i < n; i++) {
    		scanf("%d", &vec[i]);
    		//vec.push_back(temp);
    	}
    	//sort(vec.begin(),vec.end());
    	sort(vec, vec + n);
    	//int temp;
    	for (int i = 1; i <= q; i++) {
    		scanf("%d", &qq[i]);
    		m[qq[i]] = -1;
    	}
    	///memcpy(qqq,qq,sizeof(qq));
    	int *pp=vec;
    	//for (int i = 1; i <= q; i++) {
    	for(it = m.begin();it!=m.end();it++){
    		p = upper_bound(pp, vec + n, it->first);
    		if (p == vec + n) {
    			//putchar('0');
    			//puts("0");
    			//cout<<0<<endl;
    			//printf("0\n");
    			m[it->first] = 0;
    		} else {
    			//printf("%d\n", *p);
    			m[it->first] = *p;
    			//qqqq[i] = *p;
    			pp = p;
    			//cout<<*p<<endl;
    		}
    	}
    	//4 3
    	//4 1 4 9
    	//5 10 4
    /*	for(it = m.begin();it!=m.end();it++){
    		
    		cout<<it->first<<" "<<it->second<<endl;
    	}
    	*/
    	for (int i = 1; i <= q; i++) {
    		printf("%d\n", m[qq[i]]);	
    	}
    	
    	
    	return 0;
    }
    

    信息

    ID
    170
    时间
    2000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    15
    已通过
    0
    上传者