Advertisement
STEFAN_STOYANOV

red

Jan 25th, 2023 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int maxn=1e5+10;
  5. struct Trie{
  6. int cnt;
  7. map<int,Trie*>child;
  8. Trie *par,*fail,*open;
  9. Trie(){
  10. cnt=0;
  11. par=NULL;
  12. fail=NULL;
  13. open=NULL;
  14. }
  15. };
  16.  
  17. void insert_seq(Trie *&T,list<int>&seq,list<int>::iterator it){
  18. cout<<"the trie is "<<T<<"\n";
  19. if(it==seq.end()){
  20. ++T->cnt;
  21. return;
  22. }
  23. int w=*it;
  24. cout<<"with num "<<w<<endl;
  25. if(T->child.find(w)==T->child.end()){
  26. cout<<"there is not a num like that. Creating a new one.\n";
  27. T->child[w]=new Trie();
  28. T->child[w]->par=T;
  29. cout<<"Its value: "<<T->child[w]<<"\n";
  30. }
  31. insert_seq(T->child[w],seq,it++);
  32. }
  33.  
  34. void print_trie(Trie *&T,vector<int>&seq){
  35. if(T->child.size()==0){
  36. for(auto i:seq)
  37. cout<<i<<' ';
  38. cout<<endl;
  39. return;
  40. }
  41. for(auto it=T->child.begin();it!=T->child.end();++it){
  42. seq.push_back(it->first);
  43. print_trie(it->second,seq);
  44. seq.pop_back();
  45. }
  46. }
  47.  
  48. Trie* gTrie;
  49. int w,k;
  50. int n,m,a[maxn],b[maxn];
  51. void read(){
  52. cout<<"Reading begun\n";
  53. cin>>w>>k;
  54. cin>>n;
  55. for(int i=0;i<n;++i)
  56. cin>>a[i];
  57. cin>>m;
  58. for(int i=0;i<m;++i)
  59. cin>>b[i];
  60. cout<<"reading done\n";
  61. }
  62.  
  63. void show_seq(list<int>&li){
  64. for(auto it=li.begin();it!=li.end();++it)
  65. cout<<*it<<" ";
  66. cout<<endl;
  67. }
  68.  
  69. void buildtrie1(){
  70. cout<<"Here1\n";
  71. list<int>inds;
  72. list<int>seq;
  73. seq.push_back(a[0]);
  74. inds.push_back(0);
  75. cout<<"Here2\n";
  76. for(int i=1;i<n;++i){
  77. while(!inds.empty()&&inds.front()<i-k+1){
  78. inds.pop_front();
  79. seq.pop_front();
  80. }
  81. if(!seq.empty())
  82. if(seq.back()>=a[i]){
  83. seq.clear();
  84. inds.clear();
  85. }
  86. seq.push_back(a[i]);
  87. inds.push_back(i);
  88. if(seq.size()==k)
  89. {
  90. cout<<"There is a sequence\n";
  91. show_seq(seq);
  92. insert_seq(gTrie,seq,seq.begin());
  93. cout<<"It is successfully inserted\n";
  94. }
  95.  
  96. }
  97. }
  98.  
  99. /*void buildtrie2(){
  100. gTrie=new Trie();
  101. list<int>inds;
  102. list<int>seq;
  103. seq.push_back(a[0]);
  104. inds.push_back(0);
  105. for(int i=1;i<n;++i){
  106. while(!inds.empty()&&inds.front()<i-k+1){
  107. inds.pop_front();
  108. seq.pop_front();
  109. }
  110. }
  111. }*/
  112. int main()
  113. {
  114. /*ios_base::sync_with_stdio(false);
  115. cin.tie(NULL);
  116. cout.tie(NULL);*/
  117. cout<<"Start of the program\n";
  118. gTrie=new Trie();
  119. read();
  120. buildtrie1();
  121. vector<int>v;
  122. print_trie(gTrie,v);
  123. return 0;
  124. }
  125. /*
  126. 1 2
  127. 6
  128. 2 1 3 4 3 6
  129. 6
  130. 3 6 1 3 6 7
  131. */
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement