結果

問題 No.2020 Sum of Common Prefix Length
ユーザー 👑 potato167potato167
提出日時 2022-07-22 22:18:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,381 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 212,356 KB
実行使用メモリ 75,984 KB
最終ジャッジ日時 2023-09-17 10:33:57
合計ジャッジ時間 8,967 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 70 ms
7,564 KB
testcase_08 AC 72 ms
7,604 KB
testcase_09 AC 70 ms
7,552 KB
testcase_10 AC 70 ms
7,516 KB
testcase_11 AC 71 ms
7,596 KB
testcase_12 AC 72 ms
7,552 KB
testcase_13 AC 72 ms
7,528 KB
testcase_14 AC 69 ms
7,560 KB
testcase_15 AC 106 ms
17,256 KB
testcase_16 AC 107 ms
17,300 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 217 ms
75,384 KB
testcase_22 AC 220 ms
58,176 KB
testcase_23 AC 200 ms
57,204 KB
testcase_24 AC 226 ms
74,760 KB
testcase_25 AC 236 ms
74,720 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 87 ms
10,604 KB
testcase_29 AC 92 ms
11,096 KB
testcase_30 AC 91 ms
10,512 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 98 ms
20,988 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}


namespace po167{
template<int char_size,int base>
struct Trie_Tree
{
	struct Node{
		std::vector<int> next_node;
		std::vector<int> accept_node;
		int parent_node;
		int char_number;
		int cou;
		Node(int c_):next_node(char_size),char_number(c_),parent_node(-1),cou(0){
			for(int i=0;i<char_size;i++) next_node[i]=-1;
		}
	};
	std::vector<Node> nodes;
	Trie_Tree(){
		nodes.push_back(Node(-1));
	}
	vector<int> insert(std::string &word,int word_id){
		int node_id=0;
		vector<int> ids;
		for(int i=0;i<(int)word.size();i++){
			int c=(int)(word[i]-base);
			int next_id=nodes[node_id].next_node[c];
			if(next_id==-1){
				next_id=(int)nodes.size();
				nodes.push_back(Node(c));
			}
			nodes[next_id].cou++;
			nodes[next_id].parent_node=node_id;
			nodes[node_id].next_node[c]=next_id;
			nodes[next_id].accept_node.push_back(word_id);
			node_id=next_id;
			ids.push_back(node_id);
		}
		return ids;
	}
	int min_insert(char ch,int node_id,int word_id){
		int c=(int)(ch-base);
		int next_id=nodes[node_id].next_node[c];
		if(next_id==-1){
			next_id=(int)nodes.size();
			nodes.push_back(Node(c));
		}
		nodes[next_id].cou++;
		nodes[next_id].parent_node=node_id;
		nodes[node_id].next_node[c]=next_id;
		nodes[next_id].accept_node.push_back(word_id);
		node_id=next_id;
		return node_id;
	}
};
}
using po167::Trie_Tree;




void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N;
	cin>>N;
	string S;
	vector<vector<int>> ids(N);
	po167::Trie_Tree<26,(int)('a')> T;
	rep(i,N){
		string S;
		cin>>S;
		ids[i]=T.insert(S,i);
		//vec_out(ids[i]);
	}
	//cout<<endl;
	int Q;
	cin>>Q;
	vector<ll> base(N);
	int B=600;
	rep(i,N){
		for(int j=B;j<(int)(ids[i].size());j++){
			base[i]+=(int)(T.nodes[ids[i][j]].accept_node.size());
		}
	}
	rep(i,Q){
		int t,ind;
		cin>>t>>ind;
		ind--;
		if(t==1){
			char c;
			cin>>c;
			int tmp=T.min_insert(c,(*ids[ind].rbegin()),ind);
			if((int)(ids[ind].size())>=B){
				base[ind]++;
				for(auto x:T.nodes[tmp].accept_node) base[x]++,base[ind]++;
			}
			ids[ind].push_back(tmp);
		}else{
			ll ans=base[ind];
			rep(j,min((int)(ids[ind].size()),B)) ans+=(ll)(T.nodes[ids[ind][j]].accept_node.size());
			cout<<ans<<"\n";
		}
	}
}

0