-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path26086.h
57 lines (51 loc) · 1.18 KB
/
26086.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
int N, Q, k;
int input[2][100000];
deque<int> D;
int main_26086() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
cin >> Q;
cin >> k;
int lastSort = -1;
for(int i=0;i<Q;i++){
cin >> input[0][i];
if(input[0][i] == 0)
cin >> input[1][i];
if(input[0][i] == 1)
lastSort = i;
}
int command;
int uniqueN;
bool isForward = true;
for(int i=0;i<Q;i++){
command = input[0][i];
if(command == 0){
uniqueN = input[1][i];
if(isForward)
D.push_front(uniqueN);
else
D.push_back(uniqueN);
}
else if(command == 1){
if(i == lastSort){
if(isForward)
sort(D.begin(), D.end());
else
sort(D.begin(), D.end(), greater<int>());
}
}
else if(command == 2){
isForward = !isForward;
}
}
if(isForward)
cout << D[k-1] << endl;
else
cout << D[D.size()-k] << endl;
return 0;
}