Submission #72361532
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+6;
int n,a[N],q;
inline int query(int x,int y){
int l=x,r=3e9+9,ans=r;
while(l<=r){
int mid=l+r>>1;
int begin=lower_bound(a+1,a+n+1,x)-a;
int end=upper_bound(a+1,a+n+1,mid)-a-1;
int in=max(end-begin+1,(long long)0);
if(mid-x+1-in>=y)r=mid-1,ans=mid;
else l=mid+1;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
while(q--){
int x,y;cin>>x>>y;
cout<<query(x,y)<<'\n';
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Forbidden List 2 |
| User | kac17 |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 618 Byte |
| Status | AC |
| Exec Time | 1033 ms |
| Memory | 6048 KiB |
Compile Error
./Main.cpp: In function 'long long int query(long long int, long long int)':
./Main.cpp:9:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
9 | int mid=l+r>>1;
| ~^~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3424 KiB |
| 00-sample-02.txt | AC | 1 ms | 3592 KiB |
| 01-01.txt | AC | 5 ms | 3508 KiB |
| 01-02.txt | AC | 7 ms | 3508 KiB |
| 01-03.txt | AC | 7 ms | 3472 KiB |
| 01-04.txt | AC | 5 ms | 3448 KiB |
| 01-05.txt | AC | 9 ms | 3628 KiB |
| 01-06.txt | AC | 10 ms | 3620 KiB |
| 01-07.txt | AC | 6 ms | 3628 KiB |
| 01-08.txt | AC | 8 ms | 3680 KiB |
| 01-09.txt | AC | 9 ms | 3680 KiB |
| 01-10.txt | AC | 7 ms | 3552 KiB |
| 01-11.txt | AC | 8 ms | 3772 KiB |
| 01-12.txt | AC | 9 ms | 3628 KiB |
| 01-13.txt | AC | 633 ms | 5988 KiB |
| 01-14.txt | AC | 1005 ms | 5944 KiB |
| 01-15.txt | AC | 1033 ms | 6048 KiB |
| 01-16.txt | AC | 307 ms | 4636 KiB |
| 01-17.txt | AC | 923 ms | 5984 KiB |
| 01-18.txt | AC | 704 ms | 5240 KiB |
| 01-19.txt | AC | 552 ms | 5868 KiB |
| 01-20.txt | AC | 573 ms | 5992 KiB |