不知道怎么错了

P2249 【深基13.例1】查找

fez1 @ 2024-04-28 19:36:19

有没有大佬告诉我怎么出错了qwq看了好久没看出来```cpp

include<cmath>

include<iostream>

using namespace std; long long a[1000001]; long long b[1000001]; int main() { long long n; cin>>n; long long m; cin>>m; for(long long i=0;i<n;i++) cin>>a[i]; for(long long i=0;i<m;i++) cin>>b[i]; int i=0; while(m--) {
long long r=n-1; long long l=0; int mid=(r+l)/2; while(1) { if(b[i]==a[mid]) { if(b[i]!=a[mid-1]) { cout<<mid+1<<" "; break; } else mid--; } if(b[i]<a[mid]) { if(r!=mid) { r=mid; mid=(r+l)/2; } else { cout<<-1<<" "; break; } } if(b[i]>a[mid]) { if(l!=mid) { l=mid+1; mid=(r+l)/2;
} else { cout<<-1<<" "; break; } } } i++; } }


by kongyanxiang @ 2024-04-28 19:59:15

@fez1 错在没使用 Markdown


by fez1 @ 2024-04-28 21:18:41

@kongyanxiang thank you


|