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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int , int> , null_type, less<pair<int , int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
std::vector<int> countScans(std::vector<int> a,std::vector<int> X,std::vector<int> V){
int Q=X.size();
int n = a.size();
std::vector<int> answer(Q);
priority_queue<int> q[101];
orderedSet s;
bool subtrask_penal = 1;
for (int i = 0; i < n; i++)
{
s.insert ({a[i] , i});
if (a[i] > 100) subtrask_penal = 0;
else q[a[i]].push(i);
}
if (subtrask_penal) {
for (int j = 0; j < Q; j++)
{
s.erase({a[X[j]] , X[j]});
a[X[j]] = V[j];
s.insert({a[X[j]] , X[j]});
q[a[X[j]]].push(X[j]);
for (int val = 1; val <= 100; val++)
{
while (q[val].size() && a[q[val].top()] != val) q[val].pop();
if (q[val].size())
{
answer[j] = max(answer[j] , q[val].top() - (int)s.order_of_key({val, q[val].top()}));
}
}
}
}
else {
vector<pair<int, int> > crt;
for (int i = 0; i < Q; i++)
{
a[X[i]] = V[i];
// cout << X[i] << ' ' << V[i] << '\n';
vector<pair<int , int> > nou(n);
for (int j = 0; j < n; j++)
{
nou[j] = {a[j] , j};
// cout << A[j] << ' ';
}
sort(nou.begin(), nou.end());
for (int j = 0; j < n; j++)
{
answer[i] = max(answer[i] , nou[j].second - j);
}
}
}
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... |