이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
int solve(const vector<int> &A) {
const int N = A.size();
vector<int> stk = {0};
int best = 0;
for (int i = 1; i < N; ++i) {
if (A[i] > A[stk.back()]) {
stk.push_back(i);
} else if (A[i] < A[stk.back()]) {
/*int st = 0, dr = (int)stk.size() - 2;
while (st <= dr) {
const int mid = (st + dr) / 2;
if (A[i] < A[stk[mid]]) {
dr = i - 1;
} else {
st = i + 1;
}
}
best = max(best, i - stk[dr + 1]);*/
int j = stk.size() - 1;
while (j > 0 && A[i] < A[stk[j - 1]]) {
--j;
}
best = max(best, i - stk[j]);
}
}
return best;
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int Q = X.size();
vector<int> answer(Q);
for (int j = 0; j < Q; j++) {
A[X[j]] = V[j];
answer[j] = solve(A);
}
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... |