#include<bits/stdc++.h>
using namespace std;
long long f[222312],N=222312,p,k;
priority_queue<long long>q;
void upd(int i, int value)
{
while(i<N)
{
f[i]+=value;
i+=(i & -i);
}
}
int sum(int i)
{
int s=0;
while(i)
{
s+=f[i];
i-=(i & -i);
}
return s;
}
long long i,j,mx,ans,n;
long long d[223123];
vector<long long>v[213213];
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>d[i];
v[d[i]].push_back(i);
}
for(i=1;i<=n;i++)
upd(i,1);
for(i=n;i>0;i--)
{
for(j=0;j<v[i].size();j++)
q.push(v[i][j]);
if(q.size()==0)
{
cout<<-1;
return 0;
}
mx=q.top();
q.pop();
upd(n-mx+1,-1);
ans+=sum(n-mx+1);
}
cout<<ans;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(j=0;j<v[i].size();j++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5504 KB |
Output is correct |
2 |
Correct |
7 ms |
5504 KB |
Output is correct |
3 |
Correct |
7 ms |
5504 KB |
Output is correct |
4 |
Correct |
7 ms |
5504 KB |
Output is correct |
5 |
Correct |
7 ms |
5504 KB |
Output is correct |
6 |
Correct |
7 ms |
5504 KB |
Output is correct |
7 |
Correct |
7 ms |
5632 KB |
Output is correct |
8 |
Correct |
7 ms |
5632 KB |
Output is correct |
9 |
Correct |
7 ms |
5632 KB |
Output is correct |
10 |
Correct |
7 ms |
5632 KB |
Output is correct |
11 |
Correct |
7 ms |
5632 KB |
Output is correct |
12 |
Correct |
7 ms |
5632 KB |
Output is correct |
13 |
Correct |
7 ms |
5504 KB |
Output is correct |
14 |
Correct |
7 ms |
5504 KB |
Output is correct |
15 |
Correct |
9 ms |
5504 KB |
Output is correct |
16 |
Correct |
7 ms |
5504 KB |
Output is correct |
17 |
Correct |
7 ms |
5576 KB |
Output is correct |
18 |
Correct |
8 ms |
5504 KB |
Output is correct |
19 |
Correct |
8 ms |
5504 KB |
Output is correct |
20 |
Correct |
7 ms |
5504 KB |
Output is correct |
21 |
Correct |
7 ms |
5504 KB |
Output is correct |
22 |
Correct |
7 ms |
5504 KB |
Output is correct |
23 |
Correct |
7 ms |
5504 KB |
Output is correct |
24 |
Correct |
7 ms |
5504 KB |
Output is correct |
25 |
Correct |
8 ms |
5504 KB |
Output is correct |
26 |
Correct |
7 ms |
5504 KB |
Output is correct |
27 |
Correct |
8 ms |
5504 KB |
Output is correct |
28 |
Correct |
8 ms |
5504 KB |
Output is correct |
29 |
Correct |
7 ms |
5504 KB |
Output is correct |
30 |
Correct |
7 ms |
5504 KB |
Output is correct |
31 |
Correct |
7 ms |
5504 KB |
Output is correct |
32 |
Correct |
7 ms |
5632 KB |
Output is correct |
33 |
Correct |
7 ms |
5632 KB |
Output is correct |
34 |
Correct |
7 ms |
5504 KB |
Output is correct |
35 |
Correct |
7 ms |
5504 KB |
Output is correct |
36 |
Correct |
8 ms |
5632 KB |
Output is correct |
37 |
Correct |
7 ms |
5632 KB |
Output is correct |
38 |
Correct |
7 ms |
5504 KB |
Output is correct |
39 |
Correct |
8 ms |
5504 KB |
Output is correct |
40 |
Correct |
8 ms |
5504 KB |
Output is correct |
41 |
Correct |
7 ms |
5504 KB |
Output is correct |
42 |
Correct |
7 ms |
5504 KB |
Output is correct |
43 |
Correct |
7 ms |
5504 KB |
Output is correct |
44 |
Correct |
4 ms |
5376 KB |
Output is correct |
45 |
Correct |
4 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5504 KB |
Output is correct |
2 |
Correct |
7 ms |
5504 KB |
Output is correct |
3 |
Correct |
7 ms |
5504 KB |
Output is correct |
4 |
Correct |
7 ms |
5504 KB |
Output is correct |
5 |
Correct |
7 ms |
5504 KB |
Output is correct |
6 |
Correct |
7 ms |
5504 KB |
Output is correct |
7 |
Correct |
7 ms |
5632 KB |
Output is correct |
8 |
Correct |
7 ms |
5632 KB |
Output is correct |
9 |
Correct |
7 ms |
5632 KB |
Output is correct |
10 |
Correct |
7 ms |
5632 KB |
Output is correct |
11 |
Correct |
7 ms |
5632 KB |
Output is correct |
12 |
Correct |
7 ms |
5632 KB |
Output is correct |
13 |
Correct |
7 ms |
5504 KB |
Output is correct |
14 |
Correct |
7 ms |
5504 KB |
Output is correct |
15 |
Correct |
9 ms |
5504 KB |
Output is correct |
16 |
Correct |
7 ms |
5504 KB |
Output is correct |
17 |
Correct |
7 ms |
5576 KB |
Output is correct |
18 |
Correct |
8 ms |
5504 KB |
Output is correct |
19 |
Correct |
8 ms |
5504 KB |
Output is correct |
20 |
Correct |
7 ms |
5504 KB |
Output is correct |
21 |
Correct |
7 ms |
5504 KB |
Output is correct |
22 |
Correct |
7 ms |
5504 KB |
Output is correct |
23 |
Correct |
7 ms |
5504 KB |
Output is correct |
24 |
Correct |
7 ms |
5504 KB |
Output is correct |
25 |
Correct |
8 ms |
5504 KB |
Output is correct |
26 |
Correct |
7 ms |
5504 KB |
Output is correct |
27 |
Correct |
8 ms |
5504 KB |
Output is correct |
28 |
Correct |
8 ms |
5504 KB |
Output is correct |
29 |
Correct |
7 ms |
5504 KB |
Output is correct |
30 |
Correct |
7 ms |
5504 KB |
Output is correct |
31 |
Correct |
7 ms |
5504 KB |
Output is correct |
32 |
Correct |
7 ms |
5632 KB |
Output is correct |
33 |
Correct |
7 ms |
5632 KB |
Output is correct |
34 |
Correct |
7 ms |
5504 KB |
Output is correct |
35 |
Correct |
7 ms |
5504 KB |
Output is correct |
36 |
Correct |
8 ms |
5632 KB |
Output is correct |
37 |
Correct |
7 ms |
5632 KB |
Output is correct |
38 |
Correct |
7 ms |
5504 KB |
Output is correct |
39 |
Correct |
8 ms |
5504 KB |
Output is correct |
40 |
Correct |
8 ms |
5504 KB |
Output is correct |
41 |
Correct |
7 ms |
5504 KB |
Output is correct |
42 |
Correct |
7 ms |
5504 KB |
Output is correct |
43 |
Correct |
7 ms |
5504 KB |
Output is correct |
44 |
Correct |
4 ms |
5376 KB |
Output is correct |
45 |
Correct |
4 ms |
5376 KB |
Output is correct |
46 |
Correct |
221 ms |
13496 KB |
Output is correct |
47 |
Correct |
215 ms |
14704 KB |
Output is correct |
48 |
Correct |
203 ms |
14836 KB |
Output is correct |
49 |
Correct |
202 ms |
14836 KB |
Output is correct |
50 |
Correct |
231 ms |
14704 KB |
Output is correct |
51 |
Correct |
204 ms |
14704 KB |
Output is correct |
52 |
Correct |
200 ms |
16248 KB |
Output is correct |
53 |
Correct |
190 ms |
15992 KB |
Output is correct |
54 |
Correct |
170 ms |
15992 KB |
Output is correct |
55 |
Correct |
155 ms |
15992 KB |
Output is correct |
56 |
Correct |
169 ms |
16012 KB |
Output is correct |
57 |
Correct |
181 ms |
15992 KB |
Output is correct |
58 |
Correct |
197 ms |
14200 KB |
Output is correct |
59 |
Correct |
192 ms |
14072 KB |
Output is correct |
60 |
Correct |
198 ms |
14072 KB |
Output is correct |
61 |
Correct |
176 ms |
14072 KB |
Output is correct |
62 |
Correct |
160 ms |
14200 KB |
Output is correct |
63 |
Correct |
178 ms |
14072 KB |
Output is correct |
64 |
Correct |
209 ms |
13944 KB |
Output is correct |
65 |
Correct |
219 ms |
13940 KB |
Output is correct |
66 |
Correct |
187 ms |
13944 KB |
Output is correct |
67 |
Correct |
182 ms |
13944 KB |
Output is correct |
68 |
Correct |
205 ms |
14072 KB |
Output is correct |
69 |
Correct |
201 ms |
13944 KB |
Output is correct |
70 |
Correct |
223 ms |
14196 KB |
Output is correct |
71 |
Correct |
209 ms |
14196 KB |
Output is correct |
72 |
Correct |
203 ms |
14196 KB |
Output is correct |
73 |
Correct |
197 ms |
14196 KB |
Output is correct |
74 |
Correct |
191 ms |
14196 KB |
Output is correct |
75 |
Correct |
204 ms |
14196 KB |
Output is correct |
76 |
Correct |
185 ms |
13944 KB |
Output is correct |
77 |
Correct |
174 ms |
13856 KB |
Output is correct |
78 |
Correct |
163 ms |
15932 KB |
Output is correct |
79 |
Correct |
161 ms |
14072 KB |
Output is correct |
80 |
Correct |
204 ms |
14196 KB |
Output is correct |
81 |
Correct |
174 ms |
13804 KB |
Output is correct |
82 |
Correct |
149 ms |
15968 KB |
Output is correct |
83 |
Correct |
155 ms |
14072 KB |
Output is correct |
84 |
Correct |
220 ms |
14452 KB |
Output is correct |
85 |
Correct |
224 ms |
14452 KB |
Output is correct |
86 |
Correct |
215 ms |
14452 KB |
Output is correct |
87 |
Correct |
182 ms |
13820 KB |
Output is correct |
88 |
Correct |
211 ms |
14448 KB |
Output is correct |