From 8ab89b4660e68d60ee7730b609f4d9144f59ad84 Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Tue, 24 Sep 2024 17:56:51 -0300 Subject: [PATCH] Start doing a new problem. I had to leave while I was finishing this, I'll finish it later. --- 2015/phase2/fila.cpp | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 2015/phase2/fila.cpp diff --git a/2015/phase2/fila.cpp b/2015/phase2/fila.cpp new file mode 100644 index 0000000..94e2580 --- /dev/null +++ b/2015/phase2/fila.cpp @@ -0,0 +1,126 @@ +/* Problem URL: https://olimpiada.ic.unicamp.br/pratique/p2/2015/f2/fila/ */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +struct insertion { + int pos; + int ind; + int val; + + insertion(int pos, int ind, int val): pos(pos), + ind(ind), + val(val) {} + + bool operator<(insertion &i) { + if (ind == i.ind) { + return pos < i.pos; + } + return ind < i.ind; + } +}; + +struct query { + int type; + int pos; + ll val; + + query(int type, int pos, int val): type(type), + pos(pos), + val(val) {} +}; + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + cin >> n; + vl queue(n); + cin >> queue; + + int q; + cin >> q; + + V queries(q); + V inserts; + + rep(i, q) { + ll t, p, v; + cin >> t >> p >> v; + queries.emplace_back(t, p, v); + if (t == 0) { + inserts.emplace_back(i, p, v); + } + } + + reverse(queries.begin(), queries.end()); + sort(inserts.begin(), inserts.end()); +}