We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidreorder(vector<int>&inp,intl,intr,intcommand){vector<int>tmp(inp.begin()+l,inp.begin()+r);inp.erase(inp.begin()+l,inp.begin()+r);if(command==1){inp.insert(inp.begin(),tmp.begin(),tmp.end());}elseif(command==2){inp.insert(inp.end(),tmp.begin(),tmp.end());}}intmain(){intN,M;// get N , Mstd::cin>>N>>M;vector<int>input(N);for(inti=0;i<N;++i){cin>>input[i];}while(M--){intr,l,c;cin>>c>>l>>r;reorder(input,l-1,r,c);}cout<<abs(input[input.size()-1]-input[0])<<endl;for(constauto&i:input)cout<<i<<" ";return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array and simple queries
You are viewing a single comment's thread. Return to all comments →
c++ style: