Submission #74965803
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>int cmp(const void* x, const void* y) {int a = *(const int*)x, b = *(const int*)y;return (a > b) - (a < b);}int N, Q;int A[312345];int X[312345], Y[312345];/* A に query 以下の整数が何個あるか */int asumikana(int query) {int le = -1, g = N;while (le + 1 < g) {int m = le + (g - le) / 2;if (A[m] <= query) le = m; else g = m;}return g;}/* query 以下の正の整数で、A に含まれないものが何個あるか */int kitamuraeri(int query) {if (query <= 0) return 0;return query - asumikana(query);}int main(void) {int i;if (scanf("%d%d", &N, &Q) != 2) return 1;for (i = 0; i < N; i++) {if (scanf("%d", &A[i]) != 1) return 1;}for (i = 0; i < Q; i++) {if (scanf("%d%d", &X[i], &Y[i]) != 2) return 1;}qsort(A, N, sizeof(*A), cmp);for (i = 0; i < Q; i++) {int exclude = kitamuraeri(X[i] - 1);int l = X[i] - 1, ge = 2020202020;
#include <stdio.h>
#include <stdlib.h>
int cmp(const void* x, const void* y) {
int a = *(const int*)x, b = *(const int*)y;
return (a > b) - (a < b);
}
int N, Q;
int A[312345];
int X[312345], Y[312345];
/* A に query 以下の整数が何個あるか */
int asumikana(int query) {
int le = -1, g = N;
while (le + 1 < g) {
int m = le + (g - le) / 2;
if (A[m] <= query) le = m; else g = m;
}
return g;
}
/* query 以下の正の整数で、A に含まれないものが何個あるか */
int kitamuraeri(int query) {
if (query <= 0) return 0;
return query - asumikana(query);
}
int main(void) {
int i;
if (scanf("%d%d", &N, &Q) != 2) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &A[i]) != 1) return 1;
}
for (i = 0; i < Q; i++) {
if (scanf("%d%d", &X[i], &Y[i]) != 2) return 1;
}
qsort(A, N, sizeof(*A), cmp);
for (i = 0; i < Q; i++) {
int exclude = kitamuraeri(X[i] - 1);
int l = X[i] - 1, ge = 2020202020;
while (l + 1 < ge) {
int m = l + (ge - l) / 2;
int check = kitamuraeri(m) - exclude;
if (check >= Y[i]) ge = m; else l = m;
}
printf("%d\n", ge);
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Forbidden List 2 |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 400 |
| Code Size | 1173 Byte |
| Status | AC |
| Exec Time | 684 ms |
| Memory | 6784 KiB |
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 | 0 ms | 1680 KiB |
| 00-sample-02.txt | AC | 0 ms | 1572 KiB |
| 01-01.txt | AC | 4 ms | 1864 KiB |
| 01-02.txt | AC | 4 ms | 1836 KiB |
| 01-03.txt | AC | 5 ms | 1872 KiB |
| 01-04.txt | AC | 3 ms | 1952 KiB |
| 01-05.txt | AC | 5 ms | 1824 KiB |
| 01-06.txt | AC | 6 ms | 1700 KiB |
| 01-07.txt | AC | 3 ms | 1780 KiB |
| 01-08.txt | AC | 5 ms | 1800 KiB |
| 01-09.txt | AC | 5 ms | 1808 KiB |
| 01-10.txt | AC | 3 ms | 1800 KiB |
| 01-11.txt | AC | 4 ms | 1836 KiB |
| 01-12.txt | AC | 5 ms | 1832 KiB |
| 01-13.txt | AC | 410 ms | 5408 KiB |
| 01-14.txt | AC | 649 ms | 6748 KiB |
| 01-15.txt | AC | 684 ms | 6784 KiB |
| 01-16.txt | AC | 164 ms | 4656 KiB |
| 01-17.txt | AC | 586 ms | 6572 KiB |
| 01-18.txt | AC | 458 ms | 5224 KiB |
| 01-19.txt | AC | 312 ms | 6780 KiB |
| 01-20.txt | AC | 412 ms | 5240 KiB |