Submission #526377

#TimeUsernameProblemLanguageResultExecution timeMemory
526377Alex_tz307Bubble Sort 2 (JOI18_bubblesort2)C++17
100 / 100
3563 ms101020 KiB
#include <bits/stdc++.h> #include "bubblesort2.h" #define INF 0x3f3f3f3f using namespace std; struct ST { int n; vector<int> t, lazy; ST(int N) : n(N) { int dim = 1; while (dim < n) { dim *= 2; } dim *= 2; t.resize(dim, -INF); lazy.resize(dim); } void updateNode(int x, int v) { t[x] += v; lazy[x] += v; } void push(int x) { if (lazy[x] == 0) { return; } for (int i = 0; i < 2; ++i) { updateNode(x * 2 + i, lazy[x]); } lazy[x] = 0; } void update(int x, int lx, int rx, int st, int dr, int v) { if (st <= lx && rx <= dr) { updateNode(x, v); return; } push(x); int mid = (lx + rx) / 2; if (st <= mid) { update(x * 2, lx, mid, st, dr, v); } if (mid < dr) { update(x * 2 + 1, mid + 1, rx, st, dr, v); } t[x] = max(t[x * 2], t[x * 2 + 1]); } void update(int st, int dr, int v) { if (dr < st) { return; } update(1, 0, n - 1, st, dr, v); } int getMax() { return t[1]; } }; vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) { int n = a.size(), q = x.size(); vector<pair<int, int>> pairs; pairs.reserve(n + q); for (int i = 0; i < n; ++i) { pairs.emplace_back(a[i], i); } for (int i = 0; i < q; ++i) { pairs.emplace_back(v[i], x[i]); } sort(pairs.begin(), pairs.end()); map<pair<int, int>, int> order; order[pairs[0]] = 0; int N = 0; for (int i = 1; i < (int)pairs.size(); ++i) { if (pairs[i] != pairs[i - 1]) { N += 1; } order[pairs[i]] = N; } N += 1; ST t(N); auto update = [&](const int &index, const int &pos, const int &sgn) -> void { t.update(index, index, sgn * (INF + pos)); t.update(index + 1, N - 1, -sgn); }; for (int i = 0; i < n; ++i) { update(order[{a[i], i}], i, 1); } vector<int> sol(q); for (int i = 0; i < q; ++i) { update(order[{a[x[i]], x[i]}], x[i], -1); a[x[i]] = v[i]; update(order[{a[x[i]], x[i]}], x[i], 1); sol[i] = t.getMax(); } return sol; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...