Submission #273232

# Submission time Handle Problem Language Result Execution time Memory
273232 2020-08-19T04:32:06 Z 문홍윤(#5110) Exercise Deadlines (CCO20_day1problem2) C++17
25 / 25
141 ms 14200 KB
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long LL;

int n;
vector<int> vc[200010];
LL ans;
priority_queue<int> pq;

struct FENWICK{
    LL tree[200010];
    LL sum(int i){
        LL ans=0;
        while(i){
            ans+=tree[i];
            i-=(i&-i);
        }
        return ans;
    }
    void update(int i, LL num){
        while(i<=200000){
            tree[i]+=num;
            i+=(i&-i);
        }
    }
}fen;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        int a;
        scanf("%d", &a);
        vc[a].eb(i);
    }
    for(int i=n; i>=1; i--){
        for(auto j:vc[i])pq.push(j);
        if(!pq.size())return !printf("-1");
        int nw=pq.top();
        pq.pop();
        ans+=fen.sum(nw);
        fen.update(nw, 1);
    }
    printf("%lld", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |     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);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 5 ms 5248 KB Output is correct
4 Correct 6 ms 5248 KB Output is correct
5 Correct 6 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 7 ms 5376 KB Output is correct
8 Correct 6 ms 5280 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 9 ms 5248 KB Output is correct
17 Correct 6 ms 5248 KB Output is correct
18 Correct 6 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 6 ms 5248 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 5 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 6 ms 5248 KB Output is correct
26 Correct 6 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 6 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 6 ms 5220 KB Output is correct
34 Correct 6 ms 5248 KB Output is correct
35 Correct 7 ms 5248 KB Output is correct
36 Correct 6 ms 5248 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 7 ms 5152 KB Output is correct
39 Correct 8 ms 5248 KB Output is correct
40 Correct 6 ms 5248 KB Output is correct
41 Correct 5 ms 5088 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 KB Output is correct
2 Correct 6 ms 5248 KB Output is correct
3 Correct 5 ms 5248 KB Output is correct
4 Correct 6 ms 5248 KB Output is correct
5 Correct 6 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 7 ms 5376 KB Output is correct
8 Correct 6 ms 5280 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 7 ms 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 6 ms 5248 KB Output is correct
16 Correct 9 ms 5248 KB Output is correct
17 Correct 6 ms 5248 KB Output is correct
18 Correct 6 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 6 ms 5248 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 5 ms 5248 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 6 ms 5248 KB Output is correct
26 Correct 6 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 6 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 6 ms 5220 KB Output is correct
34 Correct 6 ms 5248 KB Output is correct
35 Correct 7 ms 5248 KB Output is correct
36 Correct 6 ms 5248 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 7 ms 5152 KB Output is correct
39 Correct 8 ms 5248 KB Output is correct
40 Correct 6 ms 5248 KB Output is correct
41 Correct 5 ms 5088 KB Output is correct
42 Correct 7 ms 5248 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 141 ms 11592 KB Output is correct
47 Correct 118 ms 11504 KB Output is correct
48 Correct 103 ms 11636 KB Output is correct
49 Correct 107 ms 11612 KB Output is correct
50 Correct 122 ms 11580 KB Output is correct
51 Correct 103 ms 11504 KB Output is correct
52 Correct 109 ms 14136 KB Output is correct
53 Correct 109 ms 14092 KB Output is correct
54 Correct 97 ms 14200 KB Output is correct
55 Correct 66 ms 14072 KB Output is correct
56 Correct 81 ms 14072 KB Output is correct
57 Correct 95 ms 14072 KB Output is correct
58 Correct 96 ms 11896 KB Output is correct
59 Correct 97 ms 11968 KB Output is correct
60 Correct 100 ms 12024 KB Output is correct
61 Correct 81 ms 11896 KB Output is correct
62 Correct 64 ms 12024 KB Output is correct
63 Correct 88 ms 11872 KB Output is correct
64 Correct 101 ms 11768 KB Output is correct
65 Correct 103 ms 11896 KB Output is correct
66 Correct 95 ms 11820 KB Output is correct
67 Correct 85 ms 11768 KB Output is correct
68 Correct 96 ms 11896 KB Output is correct
69 Correct 101 ms 11832 KB Output is correct
70 Correct 110 ms 11692 KB Output is correct
71 Correct 117 ms 11772 KB Output is correct
72 Correct 107 ms 11768 KB Output is correct
73 Correct 108 ms 11804 KB Output is correct
74 Correct 77 ms 11768 KB Output is correct
75 Correct 109 ms 11708 KB Output is correct
76 Correct 93 ms 11384 KB Output is correct
77 Correct 69 ms 9760 KB Output is correct
78 Correct 57 ms 14072 KB Output is correct
79 Correct 62 ms 11896 KB Output is correct
80 Correct 96 ms 11384 KB Output is correct
81 Correct 69 ms 9852 KB Output is correct
82 Correct 55 ms 14072 KB Output is correct
83 Correct 62 ms 11896 KB Output is correct
84 Correct 116 ms 11764 KB Output is correct
85 Correct 110 ms 11996 KB Output is correct
86 Correct 114 ms 11764 KB Output is correct
87 Correct 70 ms 9848 KB Output is correct
88 Correct 106 ms 11764 KB Output is correct