#include "bubblesort2.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T>
using ordered_set = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
using ii = pair<int, int>;
const int N = 5e5 + 100;
ordered_set<ii> bit[N];
int n;
void upd(int k, ii x) {
for(++k; k <= n; k += k & -k) bit[k].insert(x);
}
void remove(int k, ii x) {
for(++k; k <= n; k += k & -k) bit[k].erase(x);
}
int query(int k, ii x) {
int cnt = 0;
for(++k; k > 0; k -= k & -k) cnt += bit[k].order_of_key(x);
return cnt;
}
int query(int l, int r, ii x) {
return query(r, x) - query(l - 1, x);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int Q = X.size();
vector<int> answer(Q);
long long ans = 0;
n = A.size();
for(int i = 0; i < n; ++i) {
ans += query(i, ii(-A[i], -1));
upd(i, ii(-A[i], i));
}
for(int j = 0; j < Q; ++j) {
int i = X[j];
ans -= query(i, ii(-A[i], -1));
ans -= n - i - query(i, n - 1, ii(-A[i], n));
remove(i, ii(-A[i], i));
upd(i, ii(-V[j], i));
ans += query(i, ii(-V[j], -1));
ans += n - i - query(i, n - 1, ii(-V[j], n));
A[i] = V[j];
answer[j] = ans;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
148 ms |
60652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |