# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893336 | 1075508020060209tc | Exercise Deadlines (CCO20_day1problem2) | C++14 | 89 ms | 26572 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int lowbit(int x){return x&-x;}
int bit[500005];
void upd(int pl,int v){
while(pl<=500000){
bit[pl]+=v;
pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl){
ret=ret+bit[pl];
pl-=lowbit(pl);
}
return ret;
}
int n;
int ar[500005];
vector<int>e[500005];
void init(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>ar[i];
ar[i]=min(ar[i],n);
e[ar[i]].push_back(i);
}
}
signed main(){
init();
int ans=0;
priority_queue<int>pq;
for(int i=n;i>=1;i--){
for(int j=0;j<e[i].size();j++){
pq.push(e[i][j]);
}
if(pq.size()==0){cout<<-1<<"\n";return 0;}
ans+=i-pq.top()+qsum(pq.top());
upd(pq.top(),1);
pq.pop();
}
cout<<ans<<"\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |