Submission #293549

# Submission time Handle Problem Language Result Execution time Memory
293549 2020-09-08T07:48:26 Z 3zp Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
230 ms 14700 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 += i - 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 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 7 ms 5248 KB Output is correct
15 Correct 7 ms 5248 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 7 ms 5248 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
19 Correct 7 ms 5280 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 8 ms 5248 KB Output is correct
22 Correct 7 ms 5248 KB Output is correct
23 Correct 8 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 5248 KB Output is correct
26 Correct 7 ms 5248 KB Output is correct
27 Correct 7 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 7 ms 5248 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 7 ms 5248 KB Output is correct
33 Correct 7 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 7 ms 5120 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 6 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
39 Correct 7 ms 5248 KB Output is correct
40 Correct 8 ms 5248 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 3 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5248 KB Output is correct
3 Correct 7 ms 5248 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 7 ms 5248 KB Output is correct
15 Correct 7 ms 5248 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 7 ms 5248 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
19 Correct 7 ms 5280 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 8 ms 5248 KB Output is correct
22 Correct 7 ms 5248 KB Output is correct
23 Correct 8 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 5248 KB Output is correct
26 Correct 7 ms 5248 KB Output is correct
27 Correct 7 ms 5248 KB Output is correct
28 Correct 7 ms 5248 KB Output is correct
29 Correct 7 ms 5248 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 7 ms 5248 KB Output is correct
33 Correct 7 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 7 ms 5120 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 6 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
39 Correct 7 ms 5248 KB Output is correct
40 Correct 8 ms 5248 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 3 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Correct 214 ms 11884 KB Output is correct
47 Correct 220 ms 11976 KB Output is correct
48 Correct 214 ms 11936 KB Output is correct
49 Correct 216 ms 11832 KB Output is correct
50 Correct 203 ms 11880 KB Output is correct
51 Correct 196 ms 11896 KB Output is correct
52 Correct 185 ms 14500 KB Output is correct
53 Correct 188 ms 14572 KB Output is correct
54 Correct 171 ms 14572 KB Output is correct
55 Correct 152 ms 14572 KB Output is correct
56 Correct 171 ms 14700 KB Output is correct
57 Correct 171 ms 14572 KB Output is correct
58 Correct 197 ms 12400 KB Output is correct
59 Correct 196 ms 12400 KB Output is correct
60 Correct 190 ms 12400 KB Output is correct
61 Correct 180 ms 12360 KB Output is correct
62 Correct 157 ms 12400 KB Output is correct
63 Correct 177 ms 12400 KB Output is correct
64 Correct 205 ms 12268 KB Output is correct
65 Correct 205 ms 12268 KB Output is correct
66 Correct 192 ms 12216 KB Output is correct
67 Correct 183 ms 12396 KB Output is correct
68 Correct 195 ms 12268 KB Output is correct
69 Correct 197 ms 12268 KB Output is correct
70 Correct 211 ms 12012 KB Output is correct
71 Correct 213 ms 12012 KB Output is correct
72 Correct 198 ms 12012 KB Output is correct
73 Correct 199 ms 12012 KB Output is correct
74 Correct 168 ms 12140 KB Output is correct
75 Correct 204 ms 12012 KB Output is correct
76 Correct 181 ms 9848 KB Output is correct
77 Correct 173 ms 10032 KB Output is correct
78 Correct 147 ms 14572 KB Output is correct
79 Correct 149 ms 12400 KB Output is correct
80 Correct 163 ms 9852 KB Output is correct
81 Correct 170 ms 9996 KB Output is correct
82 Correct 146 ms 14572 KB Output is correct
83 Correct 152 ms 12400 KB Output is correct
84 Correct 209 ms 12088 KB Output is correct
85 Correct 219 ms 12188 KB Output is correct
86 Correct 211 ms 12052 KB Output is correct
87 Correct 175 ms 10104 KB Output is correct
88 Correct 230 ms 12056 KB Output is correct