# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
293581 | 2020-09-08T08:20:07 Z | achibasadzishvili | Exercise Deadlines (CCO20_day1problem2) | C++14 | 160 ms | 27616 KB |
#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; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 12288 KB | Output is correct |
2 | Correct | 11 ms | 12416 KB | Output is correct |
3 | Correct | 11 ms | 12416 KB | Output is correct |
4 | Correct | 10 ms | 12416 KB | Output is correct |
5 | Correct | 11 ms | 12416 KB | Output is correct |
6 | Correct | 10 ms | 12416 KB | Output is correct |
7 | Correct | 10 ms | 12288 KB | Output is correct |
8 | Correct | 10 ms | 12288 KB | Output is correct |
9 | Correct | 10 ms | 12288 KB | Output is correct |
10 | Correct | 10 ms | 12288 KB | Output is correct |
11 | Correct | 10 ms | 12288 KB | Output is correct |
12 | Correct | 10 ms | 12288 KB | Output is correct |
13 | Correct | 10 ms | 12288 KB | Output is correct |
14 | Correct | 10 ms | 12288 KB | Output is correct |
15 | Correct | 10 ms | 12288 KB | Output is correct |
16 | Correct | 10 ms | 12288 KB | Output is correct |
17 | Correct | 10 ms | 12288 KB | Output is correct |
18 | Correct | 10 ms | 12288 KB | Output is correct |
19 | Correct | 10 ms | 12288 KB | Output is correct |
20 | Correct | 11 ms | 12288 KB | Output is correct |
21 | Correct | 10 ms | 12288 KB | Output is correct |
22 | Correct | 10 ms | 12288 KB | Output is correct |
23 | Correct | 10 ms | 12288 KB | Output is correct |
24 | Correct | 10 ms | 12288 KB | Output is correct |
25 | Correct | 11 ms | 12288 KB | Output is correct |
26 | Correct | 11 ms | 12288 KB | Output is correct |
27 | Correct | 10 ms | 12288 KB | Output is correct |
28 | Correct | 11 ms | 12288 KB | Output is correct |
29 | Correct | 10 ms | 12288 KB | Output is correct |
30 | Correct | 10 ms | 12288 KB | Output is correct |
31 | Correct | 10 ms | 12288 KB | Output is correct |
32 | Correct | 10 ms | 12544 KB | Output is correct |
33 | Correct | 10 ms | 12288 KB | Output is correct |
34 | Correct | 10 ms | 12288 KB | Output is correct |
35 | Correct | 11 ms | 12416 KB | Output is correct |
36 | Correct | 11 ms | 12416 KB | Output is correct |
37 | Correct | 9 ms | 12288 KB | Output is correct |
38 | Correct | 10 ms | 12288 KB | Output is correct |
39 | Correct | 10 ms | 12416 KB | Output is correct |
40 | Correct | 10 ms | 12416 KB | Output is correct |
41 | Correct | 10 ms | 12416 KB | Output is correct |
42 | Correct | 10 ms | 12288 KB | Output is correct |
43 | Correct | 10 ms | 12288 KB | Output is correct |
44 | Correct | 9 ms | 12032 KB | Output is correct |
45 | Correct | 9 ms | 12032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 12288 KB | Output is correct |
2 | Correct | 11 ms | 12416 KB | Output is correct |
3 | Correct | 11 ms | 12416 KB | Output is correct |
4 | Correct | 10 ms | 12416 KB | Output is correct |
5 | Correct | 11 ms | 12416 KB | Output is correct |
6 | Correct | 10 ms | 12416 KB | Output is correct |
7 | Correct | 10 ms | 12288 KB | Output is correct |
8 | Correct | 10 ms | 12288 KB | Output is correct |
9 | Correct | 10 ms | 12288 KB | Output is correct |
10 | Correct | 10 ms | 12288 KB | Output is correct |
11 | Correct | 10 ms | 12288 KB | Output is correct |
12 | Correct | 10 ms | 12288 KB | Output is correct |
13 | Correct | 10 ms | 12288 KB | Output is correct |
14 | Correct | 10 ms | 12288 KB | Output is correct |
15 | Correct | 10 ms | 12288 KB | Output is correct |
16 | Correct | 10 ms | 12288 KB | Output is correct |
17 | Correct | 10 ms | 12288 KB | Output is correct |
18 | Correct | 10 ms | 12288 KB | Output is correct |
19 | Correct | 10 ms | 12288 KB | Output is correct |
20 | Correct | 11 ms | 12288 KB | Output is correct |
21 | Correct | 10 ms | 12288 KB | Output is correct |
22 | Correct | 10 ms | 12288 KB | Output is correct |
23 | Correct | 10 ms | 12288 KB | Output is correct |
24 | Correct | 10 ms | 12288 KB | Output is correct |
25 | Correct | 11 ms | 12288 KB | Output is correct |
26 | Correct | 11 ms | 12288 KB | Output is correct |
27 | Correct | 10 ms | 12288 KB | Output is correct |
28 | Correct | 11 ms | 12288 KB | Output is correct |
29 | Correct | 10 ms | 12288 KB | Output is correct |
30 | Correct | 10 ms | 12288 KB | Output is correct |
31 | Correct | 10 ms | 12288 KB | Output is correct |
32 | Correct | 10 ms | 12544 KB | Output is correct |
33 | Correct | 10 ms | 12288 KB | Output is correct |
34 | Correct | 10 ms | 12288 KB | Output is correct |
35 | Correct | 11 ms | 12416 KB | Output is correct |
36 | Correct | 11 ms | 12416 KB | Output is correct |
37 | Correct | 9 ms | 12288 KB | Output is correct |
38 | Correct | 10 ms | 12288 KB | Output is correct |
39 | Correct | 10 ms | 12416 KB | Output is correct |
40 | Correct | 10 ms | 12416 KB | Output is correct |
41 | Correct | 10 ms | 12416 KB | Output is correct |
42 | Correct | 10 ms | 12288 KB | Output is correct |
43 | Correct | 10 ms | 12288 KB | Output is correct |
44 | Correct | 9 ms | 12032 KB | Output is correct |
45 | Correct | 9 ms | 12032 KB | Output is correct |
46 | Correct | 152 ms | 23800 KB | Output is correct |
47 | Correct | 156 ms | 23800 KB | Output is correct |
48 | Correct | 124 ms | 23800 KB | Output is correct |
49 | Correct | 129 ms | 23800 KB | Output is correct |
50 | Correct | 130 ms | 23800 KB | Output is correct |
51 | Correct | 123 ms | 23804 KB | Output is correct |
52 | Correct | 114 ms | 22776 KB | Output is correct |
53 | Correct | 113 ms | 22776 KB | Output is correct |
54 | Correct | 86 ms | 22776 KB | Output is correct |
55 | Correct | 67 ms | 22776 KB | Output is correct |
56 | Correct | 86 ms | 22648 KB | Output is correct |
57 | Correct | 90 ms | 22780 KB | Output is correct |
58 | Correct | 108 ms | 20728 KB | Output is correct |
59 | Correct | 114 ms | 20856 KB | Output is correct |
60 | Correct | 107 ms | 20728 KB | Output is correct |
61 | Correct | 95 ms | 20784 KB | Output is correct |
62 | Correct | 69 ms | 20728 KB | Output is correct |
63 | Correct | 89 ms | 20728 KB | Output is correct |
64 | Correct | 110 ms | 20856 KB | Output is correct |
65 | Correct | 109 ms | 20728 KB | Output is correct |
66 | Correct | 99 ms | 20728 KB | Output is correct |
67 | Correct | 92 ms | 20728 KB | Output is correct |
68 | Correct | 99 ms | 20984 KB | Output is correct |
69 | Correct | 108 ms | 20728 KB | Output is correct |
70 | Correct | 121 ms | 21620 KB | Output is correct |
71 | Correct | 123 ms | 21748 KB | Output is correct |
72 | Correct | 118 ms | 21740 KB | Output is correct |
73 | Correct | 116 ms | 21620 KB | Output is correct |
74 | Correct | 83 ms | 21676 KB | Output is correct |
75 | Correct | 112 ms | 21620 KB | Output is correct |
76 | Correct | 88 ms | 21296 KB | Output is correct |
77 | Correct | 100 ms | 27616 KB | Output is correct |
78 | Correct | 58 ms | 22776 KB | Output is correct |
79 | Correct | 64 ms | 20728 KB | Output is correct |
80 | Correct | 121 ms | 22136 KB | Output is correct |
81 | Correct | 104 ms | 27616 KB | Output is correct |
82 | Correct | 58 ms | 22776 KB | Output is correct |
83 | Correct | 66 ms | 20856 KB | Output is correct |
84 | Correct | 144 ms | 22876 KB | Output is correct |
85 | Correct | 143 ms | 22904 KB | Output is correct |
86 | Correct | 152 ms | 22904 KB | Output is correct |
87 | Correct | 71 ms | 18936 KB | Output is correct |
88 | Correct | 160 ms | 22844 KB | Output is correct |