# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746490 | nguyentunglam | Bubble Sort 2 (JOI18_bubblesort2) | C++17 | 9046 ms | 2060 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 01;
int f[N];
vector<int> countScans(vector<int> a, vector<int> pos, vector<int> val) {
vector<int> ans(pos.size());
int n = a.size();
for(int j = 0; j < n; j++) for(int k = 0; k < n; k++) f[j] += (a[j] >= a[k]);
for(int i = 0; i < pos.size(); i++) {
int idx = pos[i];
for(int j = 0; j < n; j++) f[j] -= (a[j] >= a[idx]);
a[idx] = val[i];
for(int j = idx + 1; j < n; j++) f[j] += (a[j] >= a[idx]);
f[idx] = 0;
for(int j = 0; j < n; j++) f[idx] += (a[idx] >= a[j]);
for(int j = 0; j < n; j++) ans[i] = max(ans[i], j + 1 - f[j]);
}
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, q; cin >> n >> q;
vector<int> a(n), x(q), v(q);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < q; i++) cin >> x[i] >> v[i];
vector<int> ret = countScans(a, x, v);
for(int &j : ret) cout << j << endl;
}
#endif // ngu
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |