This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=5e5+5;
int dp[nx];
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int Q=X.size(), N=A.size();
vector<int> answer(Q);
for (int i=0; i<N; i++) for (int j=0; j<i; j++) if (A[j]>A[i]) dp[i]++;
for (int i=0; i<Q; i++) {
int idx=X[i], vl=V[i], ans=0;
for (int j=idx+1; j<N; j++) if (A[idx]>A[j]) dp[j]--;
dp[idx]=0;
A[idx]=vl;
for (int j=0; j<idx; j++) if (A[j]>A[idx]) dp[idx]++;
for (int j=0; j<N; j++) ans=max(ans, dp[j]);
answer[i]=ans;
}
return answer;
}
# | 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... |