#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "bubblesort2.h"
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 5e4 + 1;
int A[N];
set<int> s;
map<int, ordered_set> d;
map<int, int> ans;
int rebuild(int x, int i, int t) {
ans[x] = 0;
int j = *d[x].rbegin();
int mx = 0;
for (auto e : s) {
if (e > x) ans[x] += d[e].order_of_key(j);
if (x > e && *d[e].rbegin() > i) ans[e] += t;
mx = max(mx, ans[e]);
}
return max(mx, ans[x]);
}
int add(int i, int x) {
int p = A[i];
d[p].erase(i);
d[x].insert(i);
s.insert(x);
if (d[p].empty()) s.erase(p);
else rebuild(p, i, -1);
int mx = rebuild(x, i, 1);
A[i] = x;
return mx;
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
int n = a.size();
for (int i = 0; i < n; i++) {
add(i, a[i]);
}
int q = x.size();
vector<int> answer(q);
for (int j = 0; j < q; j++) {
answer[j] = add(x[j], v[j]);
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
1896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |