#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
int n, q, a[M], u[M], v[M], bit[M] , m = 0;
void upd(int idx)
{
while(idx <= m) {
bit[idx]++;
idx += idx&(-idx);
}
}
int get(int idx) {
int res = 0;
while(idx > 0) {
res += bit[idx];
idx -= idx&(-idx);
}
return res;
}
vector<int> rrh;
int f[M];
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
n = A.size();
q = X.size();
vector<int> ans;
cin >> n >> q;
for(int i = 1;i <= n; i++) {
a[i] = A[i - 1];
rrh.pb(a[i]);
}
for(int i = 1;i <= q; i++)
{
u[i] = X[i - 1];
v[i] = V[i - 1];
rrh.pb(v[i]);
u[i]++;
}
sort(rrh.begin(),rrh.end());
rrh.resize(unique(rrh.begin(),rrh.end()) - rrh.begin());
for(int i = 1;i <= n; i++) a[i] = lower_bound(rrh.begin(),rrh.end(),a[i]) - rrh.begin() + 1;
for(int i = 1; i <= n; i++) {
for(int j = 1;j <= i - 1; j++) {
f[i] += (a[j] > a[i]);
}
}
for(int i = 1;i <= q; i++) {
v[i] = lower_bound(rrh.begin(),rrh.end(), v[i]) - rrh.begin() + 1;
int kq = 0;
f[u[i]] = 0;
for(int j = 1;j <= u[i] - 1; j++) {
f[u[i]] += (a[j] > v[i]);
}
for(int j = u[i] + 1; j <= n; j++) {
f[j] =f[j] - (a[u[i]] > a[j]) + (v[i] > a[j]);
}
for(int i = 1;i <= n; i++) kq = max(kq, f[i]);
a[u[i]] = v[i];
ans.pb(kq);
}
return ans;
}
# | 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... |