Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #define N 200005
- using namespace std;
- ifstream fin(".in");
- ofstream fout(".out");
- int a[N], n, x,i;
- int st[N], top=0;///stiva vida
- int main()
- {
- cin>>n;
- for(i=1;i<=n;i++)
- {
- cin>>x;
- a[x]=i;///vector de pozitii
- }
- for(i=1;i<=n;i++)
- {
- cin>>x;
- if(top==0)///daca stiva este vida
- {
- cout<<a[x]<<" ";
- st[++top]=a[x];///operatia push=adaugare in stiva
- }
- else
- {
- if(a[x]>st[top])
- {
- cout<<a[x]-st[top]<<" ";
- st[++top]=a[x];
- }
- else cout<<0<<" ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement