Submission #72375933


Source Code Expand

/*
Contest Name : AtCoder Beginner Contest 440
Problem : D Forbidden List 2
Date : 2026-01-10
Time taken : 
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
const int N=1e6+6;
ll n,a[N],q;
inline ll f(ll x,ll y){
    ll l=x,r=3e9+9,ans=r;
    while(l<=r){
        ll m=l+r>>1;
        ll b=lower_bound(a+1,a+n+1,x)-a;
        ll e=upper_bound(a+1,a+n+1,m)-a-1;
        ll c=max(e-b+1,0LL);
        if(m-x+1-c>=y)r=m-1,ans=m;
        else l=m+1;
    }
    return ans;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    while(q--){
        ll x,y;cin>>x>>y;
        cout<<f(x,y)<<'\n';
    }
    return 0;
}

Submission Info

Submission Time
Task D - Forbidden List 2
User Queryme
Language C++23 (GCC 15.2.0)
Score 400
Code Size 812 Byte
Status AC
Exec Time 910 ms
Memory 5964 KiB

Compile Error

./Main.cpp: In function 'long long int f(long long int, long long int)':
./Main.cpp:19:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |         ll m=l+r>>1;
      |              ~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 22
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 3432 KiB
00-sample-02.txt AC 1 ms 3544 KiB
01-01.txt AC 5 ms 3424 KiB
01-02.txt AC 6 ms 3672 KiB
01-03.txt AC 6 ms 3416 KiB
01-04.txt AC 4 ms 3508 KiB
01-05.txt AC 8 ms 3644 KiB
01-06.txt AC 9 ms 3548 KiB
01-07.txt AC 5 ms 3628 KiB
01-08.txt AC 7 ms 3660 KiB
01-09.txt AC 8 ms 3636 KiB
01-10.txt AC 6 ms 3692 KiB
01-11.txt AC 7 ms 3740 KiB
01-12.txt AC 8 ms 3616 KiB
01-13.txt AC 551 ms 5856 KiB
01-14.txt AC 880 ms 5964 KiB
01-15.txt AC 910 ms 5944 KiB
01-16.txt AC 244 ms 4588 KiB
01-17.txt AC 800 ms 5940 KiB
01-18.txt AC 615 ms 5084 KiB
01-19.txt AC 462 ms 5920 KiB
01-20.txt AC 521 ms 5864 KiB