提出 #45706250
ソースコード 拡げる
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 ? -1 : a > b;}int zac;int zal[612345];int zaq(int q) {int l = 0, r = zac - 1;while (l <= r) {int m = l + (r - l) / 2;if (zal[m] == q) return m;else if (zal[m] < q) l = m + 1;else r = m - 1;}printf("ERROR: %d not found\n", q);exit(99);
#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 ? -1 : a > b;
}
int zac;
int zal[612345];
int zaq(int q) {
int l = 0, r = zac - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (zal[m] == q) return m;
else if (zal[m] < q) l = m + 1;
else r = m - 1;
}
printf("ERROR: %d not found\n", q);
exit(99);
}
int N;
int A[212345];
int Q;
int l[212345];
int r[212345];
char neteru[612345];
int neteru_ruiseki[612345];
int main(void) {
int i;
if (scanf("%d", &N) != 1) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &A[i]) != 1) return 1;
zal[i] = A[i];
}
if (scanf("%d", &Q) != 1) return 1;
for (i = 0; i < Q; i++) {
if (scanf("%d%d", &l[i], &r[i]) != 2) return 1;
zal[N + 2 * i + 0] = l[i];
zal[N + 2 * i + 1] = r[i];
}
qsort(zal, N + 2 * Q, sizeof(*zal), cmp);
zac = 1;
for (i = 1; i < N + 2 * Q; i++) {
if (zal[zac - 1] != zal[i]) zal[zac++] = zal[i];
}
for (i = 1; i < N; i += 2) {
neteru[zaq(A[i])]++;
neteru[zaq(A[i + 1])]--;
}
for (i = 1; i < zac; i++) {
neteru[i] += neteru[i - 1];
neteru_ruiseki[i] = neteru_ruiseki[i - 1];
if (neteru[i - 1]) neteru_ruiseki[i] += zal[i] - zal[i - 1];
}
for (i = 0; i < Q; i++) {
printf("%d\n", neteru_ruiseki[zaq(r[i])] - neteru_ruiseki[zaq(l[i])]);
}
return 0;
}
/*
0 --- 1 --- 2 +++ 3 +++ 4 +++ 5 --- 6 (index)
0 5 7 12 18 21 25 (zal)
0 0 1 1 1 0 0 (neteru)
0 0 0 5 11 14 14 (neteru_ruiseki)
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Sleep Log |
| ユーザ | mikecat |
| 言語 | C (gcc 12.2.0) |
| 得点 | 450 |
| コード長 | 1625 Byte |
| 結果 | AC |
| 実行時間 | 192 ms |
| メモリ | 9912 KB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 450 / 450 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 02_max_09.txt, 02_max_10.txt, 02_max_11.txt, 02_max_12.txt, 02_max_13.txt, 02_max_14.txt, 02_max_15.txt, 03_edge_16.txt, 03_edge_17.txt, 03_edge_18.txt, 03_edge_19.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 0 ms | 1716 KB |
| 00_sample_01.txt | AC | 0 ms | 1728 KB |
| 01_random_02.txt | AC | 23 ms | 3532 KB |
| 01_random_03.txt | AC | 56 ms | 4176 KB |
| 01_random_04.txt | AC | 137 ms | 7472 KB |
| 01_random_05.txt | AC | 31 ms | 3404 KB |
| 01_random_06.txt | AC | 88 ms | 5804 KB |
| 01_random_07.txt | AC | 137 ms | 6452 KB |
| 01_random_08.txt | AC | 108 ms | 5724 KB |
| 02_max_09.txt | AC | 192 ms | 9876 KB |
| 02_max_10.txt | AC | 190 ms | 9912 KB |
| 02_max_11.txt | AC | 192 ms | 9816 KB |
| 02_max_12.txt | AC | 190 ms | 9872 KB |
| 02_max_13.txt | AC | 190 ms | 9864 KB |
| 02_max_14.txt | AC | 185 ms | 8844 KB |
| 02_max_15.txt | AC | 186 ms | 8796 KB |
| 03_edge_16.txt | AC | 148 ms | 7300 KB |
| 03_edge_17.txt | AC | 145 ms | 6856 KB |
| 03_edge_18.txt | AC | 84 ms | 7956 KB |
| 03_edge_19.txt | AC | 84 ms | 7916 KB |