結果
| 問題 | No.3667 Prefix Count Queries |
| ユーザー |
👑 tails
|
| 提出日時 | 2026-09-01 00:48:58 |
| 言語 | C(gnu17) (gcc 15.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| + 308µs | |
| コード長 | 1,206 bytes |
| 記録 | |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 38,912 KB |
| 実行使用メモリ | 23,808 KB |
| 最終ジャッジ日時 | 2026-09-01 00:53:51 |
| 合計ジャッジ時間 | 3,142 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
コンパイルメッセージ
main.c: In function 'main':
main.c:70:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
70 | write(1,wbuf,wp-wbuf);
| ^~~~~
main.c:71:9: warning: implicit declaration of function '_exit' [-Wimplicit-function-declaration]
71 | _exit(0);
| ^~~~~
main.c:71:9: warning: incompatible implicit declaration of built-in function '_exit' [-Wbuiltin-declaration-mismatch]
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define rd_init() ({char*mmap();rp=mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) {unsigned _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define rep(v,e) for(typeof(e)v=0;v<e;++v)
char*rp;
#define TRIE_CHBASE 'a'
#define TRIE_CHNUM 26
#define TRIE_SIZE 200001
typedef struct {
int child[TRIE_CHNUM];
int count;
} TrieNode;
TrieNode trie_nodes[TRIE_SIZE];
int trie_n=1;
void trie_rd(){
int n=0;
while(1){
trie_nodes[n].count+=1;
int c=*rp++-TRIE_CHBASE;
if(c<0){
break;
}
int d=trie_nodes[n].child[c];
if(!d){
d=trie_nodes[n].child[c]=trie_n++;
}
n=d;
}
}
int h[200000];
int hn;
char wbuf[1<<25];
int main(){
char*wp=wbuf;
rd_init();
int n=rd();
rep(_,n){
trie_rd();
}
int q=rd();
rep(_,q){
int t=*rp; rp+=2;
if(t=='1'){
int c=*rp-TRIE_CHBASE; rp+=2;
int p=h[hn];
int d;
h[++hn]=p>=0&&(d=trie_nodes[p].child[c])?d:-1;
}
if(t=='2'){
--hn;
}
if(t=='3'){
int p=h[hn];
int z=p>=0?trie_nodes[p].count:0;
wt(z);
*wp++='\n';
}
}
write(1,wbuf,wp-wbuf);
_exit(0);
}
tails