跳到正文

题解

P1571 眼红的Medusa

O________O约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年9月21日
收录
2026年9月27日
更新
2026年11月10日
篇幅
约 1 分钟
获赞
1
题目
P1571

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define shabi ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n,m,a[1000010],b[1000010];
signed main(){
    shabi;
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    sort(b+1,b+m+1);
    for(int i=1;i<=n;i++){
        int k=a[i];
        int l=0,r=m+1;
        b[l]=INT_MIN,b[r]=INT_MAX;
        while(l+1<r){
            int mid=l+r>>1;
            if(b[mid]<k) l=mid;
            else r=mid;
        }if(b[r]==k) cout<<k<<" ";
    }return 0;
}
原文