# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
526611 | 2022-02-15T15:09:47 Z | Monarchuwu | Bubble Sort 2 (JOI18_bubblesort2) | C++17 | 0 ms | 0 KB |
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N = 5e5 + 5; int n, q; int a[N]; int b[N]; void update(int p, int old_val, int new_val) { b[p] = 0; for (int i = 0; i < p; ++i) b[p] += a[i] > new_val; for (int i = p + 1; i < n; ++i) { b[i] -= old_val > a[i]; b[i] += new_val > a[i]; } } int query() { return *max_element(b, b + n); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin >> n >> q; for (int i = 0; i < n; ++i) cin >> a[i], update(i, 0, a[i]); int x, v; while (q--) { cin >> x >> v; update(x, a[x], v); a[x] = v; cout << query() << '\n'; } } /** /\_/\ * (= ._.) * / >0 \>1 **/