Advertisement
nicuvlad76

Untitled

Feb 18th, 2023
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #define N 200001
  4. using namespace std;
  5. ///2650
  6. ifstream fin(".in");
  7. ofstream fout(".out");
  8.  
  9. int n, v[N],i,j,x, poz;
  10. bool st[N]; ///0 daca e si 1 daca nu este
  11.  
  12. int main()
  13. {
  14.  
  15.   cin>>n;
  16.   for(i=0; i<n; i++)cin>>v[i];
  17.   ///am presuspus ca toate elem  sunt in stiva
  18.   for(i=0; i<n; i++)
  19.   {
  20.     cin>>x;
  21.     j=poz;
  22.     if(st[x]==0)
  23.     {
  24.       j=poz;
  25.       while(v[j]!=x)
  26.       {
  27.         st[v[j]]=1;///stergere din stiva
  28.         ++j;
  29.       }
  30.       cout<<j-poz+1<<" ";
  31.       poz=j+1;
  32.     }
  33.     else cout<<0<<" ";
  34.   }
  35.  
  36.   return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement