# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309001 | giorgigagua2006 | Exercise Deadlines (CCO20_day1problem2) | C++17 | 231 ms | 16248 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.
#include<bits/stdc++.h>
using namespace std;
long long f[222312],N=222312,p,k;
priority_queue<long long>q;
void upd(int i, int value)
{
while(i<N)
{
f[i]+=value;
i+=(i & -i);
}
}
int sum(int i)
{
int s=0;
while(i)
{
s+=f[i];
i-=(i & -i);
}
return s;
}
long long i,j,mx,ans,n;
long long d[223123];
vector<long long>v[213213];
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>d[i];
v[d[i]].push_back(i);
}
for(i=1;i<=n;i++)
upd(i,1);
for(i=n;i>0;i--)
{
for(j=0;j<v[i].size();j++)
q.push(v[i][j]);
if(q.size()==0)
{
cout<<-1;
return 0;
}
mx=q.top();
q.pop();
upd(n-mx+1,-1);
ans+=sum(n-mx+1);
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |