提出 #41402522
ソースコード 拡げる
Copy
Copy
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char input_buf[12 + (5 + 12) * 512345];
- char* input_pos = input_buf;
- static const char* get_line(void) {
- const char* line = input_pos;
- char* next = strchr(input_pos, '\n');
- if (next != NULL) {
- *next = '\0';
- input_pos = next + 1;
- }
- return line;
- }
- char output_buf[12 * 512345];
- char* output_pos = output_buf;
- static void out(const char* data) {
- size_t len = strlen(data);
- memcpy(output_pos, data, len);
- output_pos += len;
- *(output_pos++) = ' ';
- }
- 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 zat[512345];
- static int zaq(int q) {
- int l = 0, r = zac - 1;
- while (l <= r) {
- int m = l + (r - l) / 2;
- if (zat[m] == q) return m;
- else if (zat[m] < q) l = m + 1;
- else r = m -1;
- }
- printf("ERROR: %d not found\n", q);
- exit(2);
- }
- int Q;
- char op[512345];
- const char* arg[512345];
- int arg_int[512345];
- struct note_node {
- struct note_node* next;
- const char* data;
- };
- struct note_node nodes[512345];
- struct note_node* A;
- struct note_node* notebook[512345];
- int main(void) {
- int i;
- int zac_raw = 0;
- size_t io_size = 0;
- for (;;) {
- size_t delta = fread(input_buf + io_size, 1, sizeof(input_buf) - io_size, stdin);
- if (delta == 0) break;
- io_size += delta;
- }
- Q = atoi(get_line());
- for (i = 0; i < Q; i++) {
- op[i] = *input_pos;
- switch (*input_pos) {
- case 'A': /* ADD */
- input_pos += 4;
- arg[i] = get_line();
- break;
- case 'D': /* DELETE */
- input_pos += 7;
- break;
- case 'S': /* SAVE */
- case 'L': /* LOAD */
- input_pos += 5;
- zat[zac_raw++] = arg_int[i] = atoi(get_line());
- break;
- default:
- printf("ERROR: %s\n", get_line());
- return 1;
- }
- }
- qsort(zat, zac_raw, sizeof(*zat), cmp);
- zac = 1;
- for (i = 1; i < zac_raw; i++) {
- if (zat[zac - 1] != zat[i]) zat[zac++] = zat[i];
- }
- for (i = 0; i < Q; i++) {
- switch (op[i]) {
- case 'A': /* ADD */
- nodes[i].next = A;
- nodes[i].data = arg[i];
- A = &nodes[i];
- break;
- case 'D': /* DELETE */
- if (A != NULL) A = A->next;
- break;
- case 'S': /* SAVE */
- notebook[zaq(arg_int[i])] = A;
- break;
- case 'L': /* LOAD */
- A = notebook[zaq(arg_int[i])];
- break;
- }
- out(A == NULL ? "-1" : A->data);
- }
- output_pos[-1] = '\n';
- io_size = output_pos - output_buf;
- while (io_size > 0) {
- size_t delta = fwrite(output_pos - io_size, 1, io_size, stdout);
- if (delta == 0) return 3;
- io_size -= delta;
- }
- return 0;
- }
- /*
- クエリを先読みしてページ番号を座標圧縮する
- 末尾しか参照しない → リストにして末尾のポインタだけ持てばおk
- 高速な方法で入出力を行うことを推奨…?
- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char input_buf[12 + (5 + 12) * 512345];
char* input_pos = input_buf;
static const char* get_line(void) {
const char* line = input_pos;
char* next = strchr(input_pos, '\n');
if (next != NULL) {
*next = '\0';
input_pos = next + 1;
}
return line;
}
char output_buf[12 * 512345];
char* output_pos = output_buf;
static void out(const char* data) {
size_t len = strlen(data);
memcpy(output_pos, data, len);
output_pos += len;
*(output_pos++) = ' ';
}
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 zat[512345];
static int zaq(int q) {
int l = 0, r = zac - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (zat[m] == q) return m;
else if (zat[m] < q) l = m + 1;
else r = m -1;
}
printf("ERROR: %d not found\n", q);
exit(2);
}
int Q;
char op[512345];
const char* arg[512345];
int arg_int[512345];
struct note_node {
struct note_node* next;
const char* data;
};
struct note_node nodes[512345];
struct note_node* A;
struct note_node* notebook[512345];
int main(void) {
int i;
int zac_raw = 0;
size_t io_size = 0;
for (;;) {
size_t delta = fread(input_buf + io_size, 1, sizeof(input_buf) - io_size, stdin);
if (delta == 0) break;
io_size += delta;
}
Q = atoi(get_line());
for (i = 0; i < Q; i++) {
op[i] = *input_pos;
switch (*input_pos) {
case 'A': /* ADD */
input_pos += 4;
arg[i] = get_line();
break;
case 'D': /* DELETE */
input_pos += 7;
break;
case 'S': /* SAVE */
case 'L': /* LOAD */
input_pos += 5;
zat[zac_raw++] = arg_int[i] = atoi(get_line());
break;
default:
printf("ERROR: %s\n", get_line());
return 1;
}
}
qsort(zat, zac_raw, sizeof(*zat), cmp);
zac = 1;
for (i = 1; i < zac_raw; i++) {
if (zat[zac - 1] != zat[i]) zat[zac++] = zat[i];
}
for (i = 0; i < Q; i++) {
switch (op[i]) {
case 'A': /* ADD */
nodes[i].next = A;
nodes[i].data = arg[i];
A = &nodes[i];
break;
case 'D': /* DELETE */
if (A != NULL) A = A->next;
break;
case 'S': /* SAVE */
notebook[zaq(arg_int[i])] = A;
break;
case 'L': /* LOAD */
A = notebook[zaq(arg_int[i])];
break;
}
out(A == NULL ? "-1" : A->data);
}
output_pos[-1] = '\n';
io_size = output_pos - output_buf;
while (io_size > 0) {
size_t delta = fwrite(output_pos - io_size, 1, io_size, stdout);
if (delta == 0) return 3;
io_size -= delta;
}
return 0;
}
/*
クエリを先読みしてページ番号を座標圧縮する
末尾しか参照しない → リストにして末尾のポインタだけ持てばおk
高速な方法で入出力を行うことを推奨…?
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Notebook |
| ユーザ | mikecat |
| 言語 | C (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 2878 Byte |
| 結果 | AC |
| 実行時間 | 166 ms |
| メモリ | 31540 KB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 43 ms | 29156 KB |
| 001.txt | AC | 14 ms | 7132 KB |
| 002.txt | AC | 162 ms | 18852 KB |
| 003.txt | AC | 166 ms | 14904 KB |
| 004.txt | AC | 156 ms | 16864 KB |
| 005.txt | AC | 134 ms | 24108 KB |
| 006.txt | AC | 108 ms | 25932 KB |
| 007.txt | AC | 83 ms | 27048 KB |
| 008.txt | AC | 60 ms | 28108 KB |
| 009.txt | AC | 107 ms | 27864 KB |
| 010.txt | AC | 92 ms | 29244 KB |
| 011.txt | AC | 79 ms | 29304 KB |
| 012.txt | AC | 65 ms | 29300 KB |
| 013.txt | AC | 52 ms | 29260 KB |
| 014.txt | AC | 34 ms | 21556 KB |
| 015.txt | AC | 36 ms | 21636 KB |
| 016.txt | AC | 38 ms | 21564 KB |
| 017.txt | AC | 38 ms | 21640 KB |
| 018.txt | AC | 37 ms | 21760 KB |
| 019.txt | AC | 35 ms | 21796 KB |
| 020.txt | AC | 37 ms | 22100 KB |
| 021.txt | AC | 35 ms | 22640 KB |
| 022.txt | AC | 36 ms | 23580 KB |
| 023.txt | AC | 37 ms | 23544 KB |
| 024.txt | AC | 106 ms | 28268 KB |
| 025.txt | AC | 81 ms | 21708 KB |
| 026.txt | AC | 21 ms | 5252 KB |
| 027.txt | AC | 63 ms | 31416 KB |
| 028.txt | AC | 70 ms | 31424 KB |
| 029.txt | AC | 71 ms | 31484 KB |
| 030.txt | AC | 72 ms | 31484 KB |
| 031.txt | AC | 74 ms | 31452 KB |
| 032.txt | AC | 68 ms | 31500 KB |
| 033.txt | AC | 75 ms | 31384 KB |
| 034.txt | AC | 76 ms | 31164 KB |
| 035.txt | AC | 76 ms | 31412 KB |
| 036.txt | AC | 63 ms | 31472 KB |
| 037.txt | AC | 69 ms | 31540 KB |
| 038.txt | AC | 70 ms | 31360 KB |
| 039.txt | AC | 73 ms | 31324 KB |
| 040.txt | AC | 72 ms | 31452 KB |
| 041.txt | AC | 45 ms | 26368 KB |
| 042.txt | AC | 46 ms | 26476 KB |
| 043.txt | AC | 46 ms | 26452 KB |
| example0.txt | AC | 3 ms | 1548 KB |
| example1.txt | AC | 2 ms | 1556 KB |