| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 293581 | achibasadzishvili | Exercise Deadlines (CCO20_day1problem2) | C++14 | 160 ms | 27616 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,a[500005];
set<ll>st;
set<ll>::iterator it;
ll b[500005],ans;
vector<ll>g[500005];
void add(ll x,ll y){
    while(y<=n){
        b[y]+=x;
    	y+=y&-y;
    }
}
ll sum(ll y){
    ll x=0;
	while(y>0){
        x+=b[y];
        y-=y&-y;
    }
    return x;
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    
    for(int i=1; i<=n; i++){
        cin >> a[i];
        g[a[i]].pb(i);
    }
    
    for(int i=n; i>=1; i--){
        for(int j=0; j<g[i].size(); j++)
            st.insert(g[i][j]);
        if(!st.size()){
            cout << -1;
            return 0;
        }
        it = st.end();
        it--;
        ll ind = (*it);
        ll w = ind;
        st.erase(it);
        ind -= sum(ind);
        ans += i - ind;
        add(1 , w);
    }
    
    cout << ans << '\n';
    
    
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
