-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookieselection.cpp
More file actions
44 lines (34 loc) · 978 Bytes
/
cookieselection.cpp
File metadata and controls
44 lines (34 loc) · 978 Bytes
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
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
#define FAST std::cin.tie(0); ios::sync_with_stdio(false); std::cout.tie(0);
using namespace std;
#define vii vector<pair<int,int>>
#define ii pair<int, int>
#define ll long long
#define TC int t; cin >> t; while (t--)
#include <bits/extc++.h>
// pbds
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
int main(int argc, char const *argv[])
{
string input;
ost tree;
int size = 0;
int ord = 0;
while (cin >> input) {
if (input == "#") {
ii output = (size % 2) ? (*tree.find_by_order((size+1)/2 - 1)) : (*tree.find_by_order(size/2));
tree.erase(output);
cout << output.first << endl;
size--;
}
else {
int k = stoi(input);
tree.insert({k, ord++});
size++;
}
}
}