codeforces 631c Report
7054 단어 acm 합숙 훈련codeforces
Employees of the “Blake Technologies” are preparing the report right now. You know the initial sequence ai of length n and the description of each manager, that is value ri and his favourite order. You are asked to speed up the process and determine how the final report will look like.
Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of commodities in the report and the number of managers, respectively.
The second line contains n integers ai (|ai| ≤ 109) — the initial report before it gets to the first manager.
Then follow m lines with the descriptions of the operations managers are going to perform. The i-th of these lines contains two integers ti and ri (, 1 ≤ ri ≤ n), meaning that the i-th manager sorts the first ri numbers either in the non-descending (if ti = 1) or non-ascending (if ti = 2) order.
Output Print n integers — the final report, which will be passed to Blake by manager number m.
Examples input 3 1 1 2 3 2 2 output 2 1 3 input 4 2 1 2 4 3 2 3 1 2 output 2 4 1 3 Note In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the report changed to: 2 4 1 3. This report was handed over to Blake.
이 문제는 정렬의 최적화, 간소화, 그리고 프로그래밍 사고에 중점을 두고 있다.밤새 썼어요.프로그래밍 사고가 중요하구나!
//
// Created by on 16/3/5.
//
#include
#include
#include
#include
#include
using namespace std;
const int max_n = 200100;
int a[max_n];
pair<int,int> op[max_n];
vectorint ,int> > v;
/*template reverse sourse code
void reverse(BidirIt first, BidirIt last)
{
while ((first != last) && (first != --last)) {
std::iter_swap(first++, last);
}
}*/
vector<int> ans;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
while (cin>>n>>m){
v.clear();
ans.clear();
for(int i = 0;icin>>a[i];
}
for(int i = 0;icin>>op[i].first>>op[i].second;
}
int pos = -1;
int op_num = 0;
for(int i = m-1;i>=0;i--){
if(op[i].second>pos){
v.push_back(op[i]);
pos = op[i].second;
op_num++;
}
}
sort(a,a+v[op_num-1].second);
//cout<
int pos_ans = 0;
reverse(v.begin(),v.end());
v.push_back(make_pair(0,0));
for(int i = n-1;i>=v[0].second;i--){
ans.push_back(a[i]);
}
int left = 0,right = v[0].second-1;
for(int i = 0;iint cnt = v[i].second-v[i+1].second;
// cout<
// cout<
for(int j = 0;jif (v[i].first==1){
ans.push_back(a[right--]);
} else{
ans.push_back(a[left++]);
// cout<
}
}
}
reverse(ans.begin(),ans.end());
for(int i = 0;icout <" " ;
}
cout<<'
';
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Gym 100231B Intervals텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.