Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("findmin.in");
- ofstream g("findmin.out");
- struct Elem{
- int val,poz;
- };
- using Sir=vector<Elem>;
- int n;
- vector<int> minn,rez;
- void citire(Sir &a,int &n)
- {
- f>>n;
- Elem x;
- for(int i=0;i<n;++i){
- f>>x.val;
- x.poz=i+1;
- a.push_back(x);
- }
- }
- void afis_poz(Sir a)
- {
- for(auto x:a)
- {
- cout<<x.poz<<" ";
- }
- cout<<endl;
- }
- void afis_val(Sir a)
- {
- for(auto x:a)
- {
- cout<<x.val<<" ";
- }
- cout<<endl;
- }
- bool cmp(Elem x,Elem y)
- {
- return (x.val<y.val);
- }
- bool myfn(Elem x, Elem y)
- {
- return x.poz<y.poz;
- }
- void rezolva(Sir a,int n)
- {
- int k;
- // g<<"-1 ";
- for(int i=0;i<n;i++)
- {
- k=a[i].poz-1;
- // minn=*min_element(a.begin(),a.begin()+k,cmp);
- if(minn[k]<a[k].poz){
- rez[k]=minn[k];
- }
- else{
- rez[k]=-1;
- }
- }
- }
- void constr_minn(Sir a) //,vector<int> &minn
- {
- int ml=a[0].poz;
- //minn.push_back(ml);
- for(auto x:a)
- {
- ml=min(ml,x.poz);
- minn.push_back(ml);
- }
- }
- int main()
- {
- Sir a,s;
- citire(a,n);
- s.resize(n);
- rez.resize(n);
- copy(a.begin(),a.end(),s.begin());
- afis_val(a);
- afis_poz(a);
- sort(a.begin(),a.end(),cmp);
- constr_minn(a);
- for(auto x:minn)
- {
- cout<<x<<" ";
- }
- cout<<'\n';
- rezolva(s,n);
- afis_val(s);
- for(auto x:rez)
- {
- cout<<x<<" ";
- }
- cout<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement