Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int maxn=1e5+10;
- struct Trie{
- int cnt;
- map<int,Trie*>child;
- Trie *par,*fail,*open;
- Trie(){
- cnt=0;
- par=NULL;
- fail=NULL;
- open=NULL;
- }
- };
- void insert_seq(Trie *&T,list<int>&seq,list<int>::iterator it){
- cout<<"the trie is "<<T<<"\n";
- if(it==seq.end()){
- ++T->cnt;
- return;
- }
- int w=*it;
- cout<<"with num "<<w<<endl;
- if(T->child.find(w)==T->child.end()){
- cout<<"there is not a num like that. Creating a new one.\n";
- T->child[w]=new Trie();
- T->child[w]->par=T;
- cout<<"Its value: "<<T->child[w]<<"\n";
- }
- insert_seq(T->child[w],seq,it++);
- }
- void print_trie(Trie *&T,vector<int>&seq){
- if(T->child.size()==0){
- for(auto i:seq)
- cout<<i<<' ';
- cout<<endl;
- return;
- }
- for(auto it=T->child.begin();it!=T->child.end();++it){
- seq.push_back(it->first);
- print_trie(it->second,seq);
- seq.pop_back();
- }
- }
- Trie* gTrie;
- int w,k;
- int n,m,a[maxn],b[maxn];
- void read(){
- cout<<"Reading begun\n";
- cin>>w>>k;
- cin>>n;
- for(int i=0;i<n;++i)
- cin>>a[i];
- cin>>m;
- for(int i=0;i<m;++i)
- cin>>b[i];
- cout<<"reading done\n";
- }
- void show_seq(list<int>&li){
- for(auto it=li.begin();it!=li.end();++it)
- cout<<*it<<" ";
- cout<<endl;
- }
- void buildtrie1(){
- cout<<"Here1\n";
- list<int>inds;
- list<int>seq;
- seq.push_back(a[0]);
- inds.push_back(0);
- cout<<"Here2\n";
- for(int i=1;i<n;++i){
- while(!inds.empty()&&inds.front()<i-k+1){
- inds.pop_front();
- seq.pop_front();
- }
- if(!seq.empty())
- if(seq.back()>=a[i]){
- seq.clear();
- inds.clear();
- }
- seq.push_back(a[i]);
- inds.push_back(i);
- if(seq.size()==k)
- {
- cout<<"There is a sequence\n";
- show_seq(seq);
- insert_seq(gTrie,seq,seq.begin());
- cout<<"It is successfully inserted\n";
- }
- }
- }
- /*void buildtrie2(){
- gTrie=new Trie();
- list<int>inds;
- list<int>seq;
- seq.push_back(a[0]);
- inds.push_back(0);
- for(int i=1;i<n;++i){
- while(!inds.empty()&&inds.front()<i-k+1){
- inds.pop_front();
- seq.pop_front();
- }
- }
- }*/
- int main()
- {
- /*ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);*/
- cout<<"Start of the program\n";
- gTrie=new Trie();
- read();
- buildtrie1();
- vector<int>v;
- print_trie(gTrie,v);
- return 0;
- }
- /*
- 1 2
- 6
- 2 1 3 4 3 6
- 6
- 3 6 1 3 6 7
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement