#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;
// using ii = pair <ll, ll>;
// using vii = vector <ii>;
const ll MAXN = 5E5+16, INF = ll(1E18)+16;
priority_queue <ll> pq[2*MAXN];
struct SegTree {
function <ll(ll, ll)> op;
ll idem;
vll tree;
ll n;
SegTree (ll n, function <ll(ll, ll)> op, ll idem): op(op), idem(idem), tree(2*n, idem), n(n) {}
void update (ll id, ll val) {
tree[id] = val;
}
void update (ll ql, ll qr, ll val) {
for (ll i = ql; i <= qr; i++) tree[i] = op(tree[i], val);
}
ll query (ll ql, ll qr) {
ll ans = idem;
for (ll i = ql; i <= qr; i++) ans = op(ans, tree[i]);
return ans;
}
};
vi countScans (vi a, vi wh, vi val) {
vll ve(a.begin(), a.end());
ll n = a.size();
ll Q = wh.size();
{vll th = ve;
for (int i : val) th.push_back(i);
sort(th.begin(), th.end());
th.resize(unique(th.begin(), th.end()) - th.begin());
for (ll &i : ve) i = lower_bound(th.begin(), th.end(), i) - th.begin() ;
for (int &i : val) i = lower_bound(th.begin(), th.end(), i) - th.begin() ;}
SegTree stFreq(1E6+16, [&](ll a, ll b){return a+b;}, 0);
SegTree stAns(1E6+16, [&](ll a, ll b){return max(a,b);}, -INF);
vi ans;
for (ll i = 0; i < n; i++) {
pq[ve[i]].push(i);
stFreq.update(ve[i], 1);
}
auto redo = [&](ll i) {
while (pq[i].size() && ve[pq[i].top()] != i) pq[i].pop();
stAns.update(i, -INF);
if (!pq[i].size()) return;
stAns.update(i, pq[i].top()+1 - stFreq.query(0, i));
};
for (ll i = 0; i < n+wh.size(); i++) redo(i);
for (ll q = 0; q < Q; q++) {
ll val1 = ve[wh[q]], val2 = val[q];
stFreq.update(ve[wh[q]], ve[wh[q]], -1);
ve[wh[q]] = val[q];
stFreq.update(ve[wh[q]], ve[wh[q]], +1);
pq[val[q]].push(wh[q]);
stAns.update(0, val1, -1);
stAns.update(0, val2, +1);
redo(val1);
redo(val2);
ans.push_back(stAns.query(0, 1E6+4));
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:59:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'long long unsigned int' [-Wsign-compare]
59 | for (ll i = 0; i < n+wh.size(); i++) redo(i);
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1499 ms |
63316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1499 ms |
63316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5317 ms |
64092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1499 ms |
63316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |