社区讨论
TLE求调
P1571眼红的Medusa参与者 2已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mlivte7n
- 此快照首次捕获于
- 2026/02/12 11:11 上周
- 此快照最后确认于
- 2026/02/14 16:25 5 天前
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define PII pair<int,int>
const int N=1e5+10;
int a[N],b[N];
int n,m;
bool check(int x){
int l=1,r=n+1;
while(l<=r){
int mid=l+(r-l)/2;
if(a[mid]>x) r=mid+1;
else if(a[mid]<x) l=mid+1;
else if(a[mid]==x) return 1;
}
if(a[l]==x){
return 1;
}else{
return 0;
}
}
void solve(){
//freopen("pow.in","r",stdin);
//freopen("pow.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=m;i++){
int x;
cin>>x;
if(check(x)){
cout<<x<<" ";
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t;
t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...