Advertisement
nicuvlad76

Untitled

Feb 11th, 2023
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #define N 200005
  5. using namespace std;
  6. ifstream fin(".in");
  7. ofstream fout(".out");
  8.  
  9. int a[N], n, x,i;
  10. int st[N], top=0;///stiva vida
  11.  
  12. int main()
  13. {
  14.    cin>>n;
  15.    for(i=1;i<=n;i++)
  16.    {
  17.        cin>>x;
  18.        a[x]=i;///vector de pozitii
  19.    }
  20.    for(i=1;i<=n;i++)
  21.    {
  22.        cin>>x;
  23.        if(top==0)///daca stiva este vida
  24.        {
  25.            cout<<a[x]<<" ";
  26.            st[++top]=a[x];///operatia push=adaugare in stiva
  27.        }
  28.        else
  29.        {
  30.            if(a[x]>st[top])
  31.            {
  32.                cout<<a[x]-st[top]<<" ";
  33.                st[++top]=a[x];
  34.            }
  35.            else cout<<0<<" ";
  36.        }
  37.    }
  38.  
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement