Submission #66046051


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Q_MAX 212345
int Q;
int T[Q_MAX];
char* S[Q_MAX];
char S_buf[512345];
struct node_s {
int pos;
struct node_s* next[26];
};
void ki_add(struct node_s** node, const char* str, int value) {
if (*node == NULL) {
*node = calloc(1, sizeof(**node));
if (*node == NULL) exit(2);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define Q_MAX 212345

int Q;
int T[Q_MAX];
char* S[Q_MAX];

char S_buf[512345];

struct node_s {
	int pos;
	struct node_s* next[26];
};

void ki_add(struct node_s** node, const char* str, int value) {
	if (*node == NULL) {
		*node = calloc(1, sizeof(**node));
		if (*node == NULL) exit(2);
		(*node)->pos = Q + 1;
	}
	if (*str < 'a' || 'a' + 26 <= *str) {
		if ((*node)->pos > value) (*node)->pos = value;
	} else {
		ki_add(&(*node)->next[*str - 'a'], str + 1, value);
	}
}

int ki_get(const struct node_s* node, const char* str) {
	if (node == NULL) {
		return Q + 1;
	} else {
		int ans = node->pos;
		if ('a' <= *str && *str < 'a' + 26) {
			int candidate = ki_get(node->next[*str - 'a'], str + 1);
			if (candidate < ans) ans = candidate;
		}
		return ans;
	}
}

int bit_table[Q_MAX];

void bit_add(int pos, int value) {
	pos++;
	while (pos <= Q_MAX) {
		bit_table[pos - 1] += value;
		pos += pos & (-pos);
	}
}

int bit_sum(int pos) {
	int sum = 0;
	pos++;
	while (pos > 0) {
		sum += bit_table[pos - 1];
		pos -= pos & (-pos);
	}
	return sum;
}

int main(void) {
	int i;
	struct node_s* root = NULL;
	if (scanf("%d", &Q) != 1) return 1;
	for (i = 0; i < Q; i++) {
		if (scanf("%d%512344s", &T[i], S_buf) != 2) return 1;
		S[i] = malloc(strlen(S_buf) + 1);
		if (S[i] == NULL) return 2;
		strcpy(S[i], S_buf);
	}
	/* X への追加を先に全て登録する */
	for (i = 0; i < Q; i++) {
		if (T[i] == 1) {
			ki_add(&root, S[i], i);
		}
	}
	/* 「どこで X に追加されるか」を管理し、それが現在かそれより前のものは引く */
	for (i = 0; i < Q; i++) {
		if (T[i]  == 2) {
			bit_add(ki_get(root, S[i]), 1);
		}
		printf("%d\n", bit_sum(Q + 10) - bit_sum(i));
	}
	return 0;
}

Submission Info

Submission Time
Task E - Forbidden Prefix
User mikecat
Language C (gcc 12.2.0)
Score 500
Code Size 1859 Byte
Status AC
Exec Time 52 ms
Memory 112052 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 57
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_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, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 1732 KB
00_sample_02.txt AC 1 ms 1740 KB
01_random_01.txt AC 2 ms 2248 KB
01_random_02.txt AC 18 ms 41928 KB
01_random_03.txt AC 19 ms 41452 KB
01_random_04.txt AC 29 ms 64180 KB
01_random_05.txt AC 41 ms 92428 KB
01_random_06.txt AC 48 ms 111588 KB
01_random_07.txt AC 2 ms 2148 KB
01_random_08.txt AC 13 ms 24952 KB
01_random_09.txt AC 22 ms 44176 KB
01_random_10.txt AC 32 ms 66132 KB
01_random_11.txt AC 40 ms 89304 KB
01_random_12.txt AC 49 ms 109320 KB
01_random_13.txt AC 3 ms 2344 KB
01_random_14.txt AC 50 ms 16132 KB
01_random_15.txt AC 51 ms 20820 KB
01_random_16.txt AC 52 ms 24088 KB
01_random_17.txt AC 47 ms 50996 KB
01_random_18.txt AC 48 ms 31264 KB
01_random_19.txt AC 8 ms 12932 KB
01_random_20.txt AC 24 ms 40620 KB
01_random_21.txt AC 28 ms 31648 KB
01_random_22.txt AC 9 ms 14488 KB
01_random_23.txt AC 29 ms 31220 KB
01_random_24.txt AC 49 ms 17168 KB
01_random_25.txt AC 33 ms 12932 KB
01_random_26.txt AC 38 ms 13780 KB
01_random_27.txt AC 18 ms 5392 KB
01_random_28.txt AC 47 ms 16900 KB
01_random_29.txt AC 38 ms 21500 KB
01_random_30.txt AC 39 ms 14824 KB
01_random_31.txt AC 27 ms 12544 KB
01_random_32.txt AC 29 ms 10172 KB
01_random_33.txt AC 15 ms 12428 KB
01_random_34.txt AC 44 ms 16024 KB
01_random_35.txt AC 32 ms 12500 KB
01_random_36.txt AC 34 ms 12416 KB
01_random_37.txt AC 39 ms 13488 KB
01_random_38.txt AC 41 ms 24220 KB
01_random_39.txt AC 40 ms 31456 KB
01_random_40.txt AC 38 ms 35776 KB
01_random_41.txt AC 36 ms 39184 KB
02_handmade_01.txt AC 47 ms 112052 KB
02_handmade_02.txt AC 2 ms 2712 KB
02_handmade_03.txt AC 36 ms 10140 KB
02_handmade_04.txt AC 35 ms 10212 KB
02_handmade_05.txt AC 6 ms 2872 KB
02_handmade_06.txt AC 6 ms 2816 KB
02_handmade_07.txt AC 4 ms 2260 KB
02_handmade_08.txt AC 4 ms 2344 KB
02_handmade_09.txt AC 5 ms 2620 KB
02_handmade_10.txt AC 5 ms 2700 KB
02_handmade_11.txt AC 12 ms 8016 KB
02_handmade_12.txt AC 12 ms 8100 KB
02_handmade_13.txt AC 34 ms 60956 KB
02_handmade_14.txt AC 34 ms 61068 KB


2025-05-23 (Fri)
00:46:37 +09:00