# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
893336 | 1075508020060209tc | Exercise Deadlines (CCO20_day1problem2) | C++14 | 89 ms | 26572 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |