Submission #293546

# Submission time Handle Problem Language Result Execution time Memory
293546 2020-09-08T07:46:41 Z 3zp Exercise Deadlines (CCO20_day1problem2) C++14
0 / 25
8 ms 5248 KB
#include<bits/stdc++.h>
using namespace std;
int a[200009],d[200009],f[200009],F[200009];
vector<int> v[200009];
int n;
int cnt(int x){
    int ans = 0;
    while(x){
        ans += F[x];
        x -= x&-x;
    }
    return ans;
}
void upd(int x){
    while(x <= n){
        F[x] ++;
        x += x&-x;
    }
}
main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
        f[d[i]]++;
        v[d[i]].push_back(i);
    }
    vector<int> a;
    priority_queue<int> q;
    for(int i = 1; i <= n; i++){
        f[i] += f[i-1];
        if(f[i] > i){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i = n; i >= 0; i--){
        while(q.size() + f[i] > i){
            a.push_back(q.top());
            q.pop();
        }
        for(int x : v[i])
            q.push(x);
    }
    long long ans = 0;
    reverse(a.begin(), a.end());
    for(int i = 0; i < a.size(); i++){
        ans += cnt(a[i]);
        upd(a[i]);
    }
    cout<<ans<<endl;



}

Compilation message

Main.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main(){
      |      ^
Main.cpp: In function 'int main()':
Main.cpp:37:31: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         while(q.size() + f[i] > i){
      |               ~~~~~~~~~~~~~~~~^~~
Main.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5248 KB Output isn't correct
2 Halted 0 ms 0 KB -