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<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>st1;
tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>st2;
#include "books.h"
//#include"grader.cpp"
long long minimum_walk(vector<int> p, int s) {
st1.clear();
st2.clear();
int n=p.size();
vector<int>seg1(n),mx(n+1);
long long res=0;
for(int i=0;i<n;i++){
st2.insert(p[i]);
seg1[i]=st2.order_of_key(i);
}
for(int i=n-1;i>=0;i--)mx[i]=max(mx[i+1],seg1[i]);
for(int i=0;i<n-1;i++){
if(seg1[i]==0&&mx[i])res+=2;
else res+=seg1[i]+seg1[i];
}
return res;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |