답안 #307220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307220 2020-09-27T11:26:06 Z NintsiChkhaidze Exercise Deadlines (CCO20_day1problem2) C++14
0 / 25
1000 ms 5120 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
#define N 200005
#define ll long long
using namespace std;
priority_queue <int> q;
int fen[200005];
vector <int> v[200005];
void upd(int in,int val){
    while (in <= N){
        fen[in]+=val;
        in += (in&(-in));
    }
}
int get(int in){
    int sum=0;
    while (in > 0){
        sum+=fen[in];
        in -= (in&(-in));
    }
    return sum;
}
int main(){
    int n;
    scanf("%d",&n);
    
    for (int i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        v[a].pb(i);
    }
 
    int ind = n;
    ll ans = 0;
    while (ind > 0){
        for (int i = 0; i < v[ind].size(); i++)
            q.push(v[ind][i]);
        
        if (q.size() == 0){
            printf("-1");
            return 0;
        }
        int x = q.top() - get(q.top());
        q.pop();
        ans+=ind - x;
        upd(x,1);
        ind--;
    }
    printf("%lld",ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 0; i < v[ind].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 5120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 5120 KB Time limit exceeded
2 Halted 0 ms 0 KB -