Submission #35681448
Source Code Expand
#include <stdio.h>
typedef struct Edge {
struct Edge *next;
int v;
} edge;
typedef struct List {
struct List *next;
int v, y;
} list;
#define HASH 1000003
const int H_Mod = HASH;
void DFS(edge* adj[], char t[][7], int x[], int u, int k, int s[], int ans[])
{
int w, tmp;
edge *p;
for (p = adj[u]; p != NULL; p = p->next) {
w = p->v;
if (t[w][0] == 'A') s[k++] = x[w];
else if (t[w][0] == 'D') {
if (k == 0) tmp = -1;
else tmp = s[--k];
}
if (k == 0) ans[w] = -1;
else ans[w] = s[k-1];
DFS(adj, t, x, w, k, s, ans);
if (t[w][0] == 'A') k--;
else if (t[w][0] == 'D') {
if (tmp >= 0) s[k++] = tmp;
}
}
}
int main()
{
int h, hn = 0, i, Q, x[500001];
char t[500001][7];
list *hash[HASH] = {}, hd[500001], *hp;
edge *adj[500001] = {}, e[500001];
scanf("%d", &Q);
for (i = 1; i <= Q; i++) {
scanf("%s", t[i]);
if (t[i][0] != 'D') scanf("%d", &(x[i]));
if (t[i][0] == 'S') {
h = x[i] % H_Mod;
for (hp = hash[h]; hp != NULL; hp = hp->next) if (hp->y == x[i]) break;
if (hp != NULL) hp->v = i;
else {
hd[hn].v = i;
hd[hn].y = x[i];
hd[hn].next = hash[h];
hash[h] = &(hd[hn++]);
}
e[i].v = i;
e[i].next = adj[i-1];
adj[i-1] = &(e[i]);
} else if (t[i][0] == 'L') {
h = x[i] % H_Mod;
for (hp = hash[h]; hp != NULL; hp = hp->next) if (hp->y == x[i]) break;
if (hp != NULL) {
e[i].v = i;
e[i].next = adj[hp->v];
adj[hp->v] = &(e[i]);
} else {
e[i].v = i;
e[i].next = adj[0];
adj[0] = &(e[i]);
}
} else {
e[i].v = i;
e[i].next = adj[i-1];
adj[i-1] = &(e[i]);
}
}
int ans[500001], s[500001];
DFS(adj, t, x, 0, 0, s, ans);
for (i = 1; i <= Q; i++) printf("%d ", ans[i]);
printf("\n");
fflush(stdout);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Notebook |
| User |
ygussany |
| Language |
C (GCC 9.2.1) |
| Score |
500 |
| Code Size |
1835 Byte |
| Status |
AC |
| Exec Time |
273 ms |
| Memory |
83492 KiB |
Compile Error
./Main.c: In function ‘main’:
./Main.c:43:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%d", &Q);
| ^~~~~~~~~~~~~~~
./Main.c:45:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
45 | scanf("%s", t[i]);
| ^~~~~~~~~~~~~~~~~
./Main.c:46:23: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
46 | if (t[i][0] != 'D') scanf("%d", &(x[i]));
| ^~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| 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 |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
172 ms |
81024 KiB |
| 001.txt |
AC |
111 ms |
73692 KiB |
| 002.txt |
AC |
225 ms |
83492 KiB |
| 003.txt |
AC |
167 ms |
28632 KiB |
| 004.txt |
AC |
273 ms |
56156 KiB |
| 005.txt |
AC |
256 ms |
63544 KiB |
| 006.txt |
AC |
233 ms |
68208 KiB |
| 007.txt |
AC |
208 ms |
72460 KiB |
| 008.txt |
AC |
184 ms |
76832 KiB |
| 009.txt |
AC |
216 ms |
68500 KiB |
| 010.txt |
AC |
208 ms |
71648 KiB |
| 011.txt |
AC |
198 ms |
73996 KiB |
| 012.txt |
AC |
188 ms |
76324 KiB |
| 013.txt |
AC |
176 ms |
78692 KiB |
| 014.txt |
AC |
149 ms |
79076 KiB |
| 015.txt |
AC |
142 ms |
55200 KiB |
| 016.txt |
AC |
138 ms |
43180 KiB |
| 017.txt |
AC |
130 ms |
37188 KiB |
| 018.txt |
AC |
127 ms |
34208 KiB |
| 019.txt |
AC |
127 ms |
32796 KiB |
| 020.txt |
AC |
125 ms |
32216 KiB |
| 021.txt |
AC |
129 ms |
32112 KiB |
| 022.txt |
AC |
127 ms |
32272 KiB |
| 023.txt |
AC |
126 ms |
32216 KiB |
| 024.txt |
AC |
157 ms |
31328 KiB |
| 025.txt |
AC |
124 ms |
26824 KiB |
| 026.txt |
AC |
45 ms |
15940 KiB |
| 027.txt |
AC |
162 ms |
61452 KiB |
| 028.txt |
AC |
157 ms |
51780 KiB |
| 029.txt |
AC |
156 ms |
46848 KiB |
| 030.txt |
AC |
155 ms |
43772 KiB |
| 031.txt |
AC |
152 ms |
41904 KiB |
| 032.txt |
AC |
152 ms |
40488 KiB |
| 033.txt |
AC |
151 ms |
39492 KiB |
| 034.txt |
AC |
152 ms |
38284 KiB |
| 035.txt |
AC |
152 ms |
38040 KiB |
| 036.txt |
AC |
163 ms |
61336 KiB |
| 037.txt |
AC |
158 ms |
51828 KiB |
| 038.txt |
AC |
157 ms |
46780 KiB |
| 039.txt |
AC |
155 ms |
43804 KiB |
| 040.txt |
AC |
153 ms |
41896 KiB |
| 041.txt |
AC |
157 ms |
79104 KiB |
| 042.txt |
AC |
156 ms |
79200 KiB |
| 043.txt |
AC |
156 ms |
79104 KiB |
| example0.txt |
AC |
15 ms |
13368 KiB |
| example1.txt |
AC |
11 ms |
13436 KiB |