Submission #72362376
Source Code Expand
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, q, a[300005];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i ++) cin >> a[i];
sort(a + 1, a + 1 + n);
a[++ n] = 1e10;
while(q --) {
int x, y;
cin >> x >> y;
int l = 1, r = n, mid, cnt;
while(l < r) {
mid = l + r >> 1;
if(a[mid] >= x) r = mid;
else l = mid + 1;
}
cnt = l;
r = n;
while(l < r) {
mid = l + r >> 1;
if(a[mid] - x - mid + cnt >= y) r = mid;
else l = mid + 1;
}
int rnk = a[l] - x - l + cnt;
cout << a[l] - 1 - (rnk - y) << '\n';
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Forbidden List 2 |
| User | WangYueHeng |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 672 Byte |
| Status | AC |
| Exec Time | 143 ms |
| Memory | 6164 KiB |
Compile Error
./Main.cpp: In function 'int main()':
./Main.cpp:17:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | mid = l + r >> 1;
| ~~^~~
./Main.cpp:24:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | 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 | 3532 KiB |
| 00-sample-02.txt | AC | 1 ms | 3588 KiB |
| 01-01.txt | AC | 2 ms | 3480 KiB |
| 01-02.txt | AC | 2 ms | 3604 KiB |
| 01-03.txt | AC | 3 ms | 3732 KiB |
| 01-04.txt | AC | 2 ms | 3620 KiB |
| 01-05.txt | AC | 2 ms | 3684 KiB |
| 01-06.txt | AC | 2 ms | 3744 KiB |
| 01-07.txt | AC | 2 ms | 3600 KiB |
| 01-08.txt | AC | 2 ms | 3552 KiB |
| 01-09.txt | AC | 2 ms | 3720 KiB |
| 01-10.txt | AC | 2 ms | 3720 KiB |
| 01-11.txt | AC | 2 ms | 3716 KiB |
| 01-12.txt | AC | 2 ms | 3608 KiB |
| 01-13.txt | AC | 85 ms | 6096 KiB |
| 01-14.txt | AC | 128 ms | 6004 KiB |
| 01-15.txt | AC | 143 ms | 5908 KiB |
| 01-16.txt | AC | 46 ms | 4616 KiB |
| 01-17.txt | AC | 132 ms | 6024 KiB |
| 01-18.txt | AC | 93 ms | 5196 KiB |
| 01-19.txt | AC | 86 ms | 6164 KiB |
| 01-20.txt | AC | 98 ms | 6072 KiB |