#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
const int MAX_N = 8000;
int a[MAX_N];
int maxpref[MAX_N], minsuff[MAX_N];
int badsegtree[MAX_N];
void update(int poz, int val, int n) {
maxpref[0] = a[0];
for(int i = 1; i < n; ++i)
maxpref[i] = max(maxpref[i - 1], a[i]);
minsuff[n - 1] = a[n - 1];
for(int i = n - 2; i >= 0; --i)
minsuff[i] = min(minsuff[i + 1], a[i]);
for(int i = 0; i < poz; ++i)
if(maxpref[i] > a[poz])
badsegtree[i] += val;
for(int i = poz; i < n - 1; ++i)
if(a[poz] > minsuff[i])
badsegtree[i] += val;
}
int getInv(int n) {
int rez = 0;
for(int i = 0; i < n; ++i)
rez = max(rez, badsegtree[i]);
return rez;
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int n, q;
q = X.size();
std::vector<int> rez(q);
n = A.size();
for(int i = 0; i < n; ++i) {
update(i, -1, n);
a[i] = A[i];
update(i, 1, n);
}
for(int i = 0; i < q; ++i) {
update(X[i], -1, n);
a[X[i]] = V[i];
update(X[i], 1, n);
rez[i] = getInv(n);
}
return rez;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
1144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |