Submission #1042038

#TimeUsernameProblemLanguageResultExecution timeMemory
1042038PM1Dabbeh (INOI20_dabbeh)C++17
0 / 100
284 ms55056 KiB
#include <bits/stdc++.h> using namespace std; const int mxn=3e5+5; int n,m,l,r,trie[mxn*2][26],cnt=0,sz[mxn*2],par[mxn*2]; string s[mxn],a; vector<int>v; void add(int d,int x,int i){ if(d==s[i].size()) return ; if(trie[x][s[i][d]-'a']==0){ trie[x][s[i][d]-'a']=++cnt; par[cnt]=x; } sz[trie[x][s[i][d]-'a']]++; add(d+1,trie[x][s[i][d]-'a'],i); } void up(int x){ while(x!=0){ sz[x]++; x=par[x]; } } void get(int x=0){ //cout<<x<<" "; if(l==r+1 || trie[x][a[l]-'a']==0 || sz[trie[x][a[l]-'a']]==0 ){ v.push_back(x); if(x==0) l=1e9; return; } sz[trie[x][a[l]-'a']]--; get(trie[x][a[l++]-'a']); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++){ cin>>s[i]; add(0,0,i); } cin>>a; while(m--){ cin>>l>>r; r--; int ans=0; while(l<r+1){ get(); ans++; } if(l==1e9) cout<<-1<<'\n'; else cout<<ans<<'\n'; while(v.size()){ up(v.back()); v.pop_back(); } } }

Compilation message (stderr)

Main.cpp: In function 'void add(int, int, int)':
Main.cpp:8:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  if(d==s[i].size())
      |     ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...