| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 526611 | Monarchuwu | Bubble Sort 2 (JOI18_bubblesort2) | C++17 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
**/
