Submission #343780

# Submission time Handle Problem Language Result Execution time Memory
343780 2021-01-04T13:20:51 Z Sho10 Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
157 ms 15852 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[200005],bit[200005];
void update(ll pos,ll val){
	for(;pos<=n;pos+=pos&(-pos)){
		bit[pos]+=val;
	}
}
ll query(ll pos){
	ll res=0;
	for(;pos;pos-=pos&(-pos)){
		res+=bit[pos];
	}
	return res;
}
vector<ll>g[200005];
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
	cin>>a[i];
	g[a[i]].pb(i);
}
for(ll i=1;i<=n;i++)
{
	update(i,1ll);
}
priority_queue<ll>q;
ll ans=0;
for(ll i=n;i>=1;i--){
	for(auto it : g[i]){
	q.push(it);
}
if(q.size()==0){
	rc("-1");
}
ll x=q.top();
q.pop();
update(n-x+1,-1);
ans+=query(n-x+1);
}
cout<<ans<<endl;
}	

# Verdict Execution time Memory Grader output
1 Correct 5 ms 5228 KB Output is correct
2 Correct 5 ms 5228 KB Output is correct
3 Correct 5 ms 5240 KB Output is correct
4 Correct 6 ms 5228 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 7 ms 5228 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 5 ms 5356 KB Output is correct
9 Correct 5 ms 5356 KB Output is correct
10 Correct 5 ms 5356 KB Output is correct
11 Correct 6 ms 5356 KB Output is correct
12 Correct 6 ms 5356 KB Output is correct
13 Correct 7 ms 5228 KB Output is correct
14 Correct 5 ms 5260 KB Output is correct
15 Correct 7 ms 5228 KB Output is correct
16 Correct 6 ms 5228 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 5 ms 5228 KB Output is correct
20 Correct 6 ms 5228 KB Output is correct
21 Correct 6 ms 5356 KB Output is correct
22 Correct 7 ms 5228 KB Output is correct
23 Correct 5 ms 5228 KB Output is correct
24 Correct 6 ms 5228 KB Output is correct
25 Correct 7 ms 5228 KB Output is correct
26 Correct 7 ms 5228 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 7 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 6 ms 5228 KB Output is correct
32 Correct 5 ms 5356 KB Output is correct
33 Correct 5 ms 5356 KB Output is correct
34 Correct 5 ms 5228 KB Output is correct
35 Correct 6 ms 5232 KB Output is correct
36 Correct 5 ms 5368 KB Output is correct
37 Correct 7 ms 5356 KB Output is correct
38 Correct 5 ms 5228 KB Output is correct
39 Correct 6 ms 5228 KB Output is correct
40 Correct 6 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 7 ms 5228 KB Output is correct
43 Correct 6 ms 5228 KB Output is correct
44 Correct 4 ms 5100 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5228 KB Output is correct
2 Correct 5 ms 5228 KB Output is correct
3 Correct 5 ms 5240 KB Output is correct
4 Correct 6 ms 5228 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 7 ms 5228 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 5 ms 5356 KB Output is correct
9 Correct 5 ms 5356 KB Output is correct
10 Correct 5 ms 5356 KB Output is correct
11 Correct 6 ms 5356 KB Output is correct
12 Correct 6 ms 5356 KB Output is correct
13 Correct 7 ms 5228 KB Output is correct
14 Correct 5 ms 5260 KB Output is correct
15 Correct 7 ms 5228 KB Output is correct
16 Correct 6 ms 5228 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 5 ms 5228 KB Output is correct
20 Correct 6 ms 5228 KB Output is correct
21 Correct 6 ms 5356 KB Output is correct
22 Correct 7 ms 5228 KB Output is correct
23 Correct 5 ms 5228 KB Output is correct
24 Correct 6 ms 5228 KB Output is correct
25 Correct 7 ms 5228 KB Output is correct
26 Correct 7 ms 5228 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 7 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 6 ms 5228 KB Output is correct
32 Correct 5 ms 5356 KB Output is correct
33 Correct 5 ms 5356 KB Output is correct
34 Correct 5 ms 5228 KB Output is correct
35 Correct 6 ms 5232 KB Output is correct
36 Correct 5 ms 5368 KB Output is correct
37 Correct 7 ms 5356 KB Output is correct
38 Correct 5 ms 5228 KB Output is correct
39 Correct 6 ms 5228 KB Output is correct
40 Correct 6 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 7 ms 5228 KB Output is correct
43 Correct 6 ms 5228 KB Output is correct
44 Correct 4 ms 5100 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 124 ms 14436 KB Output is correct
47 Correct 121 ms 14448 KB Output is correct
48 Correct 106 ms 14436 KB Output is correct
49 Correct 107 ms 14564 KB Output is correct
50 Correct 122 ms 14444 KB Output is correct
51 Correct 114 ms 14436 KB Output is correct
52 Correct 117 ms 15724 KB Output is correct
53 Correct 129 ms 15724 KB Output is correct
54 Correct 102 ms 15724 KB Output is correct
55 Correct 58 ms 15852 KB Output is correct
56 Correct 76 ms 15724 KB Output is correct
57 Correct 81 ms 15724 KB Output is correct
58 Correct 105 ms 13784 KB Output is correct
59 Correct 105 ms 13804 KB Output is correct
60 Correct 99 ms 13804 KB Output is correct
61 Correct 94 ms 13804 KB Output is correct
62 Correct 72 ms 13676 KB Output is correct
63 Correct 82 ms 13804 KB Output is correct
64 Correct 117 ms 13676 KB Output is correct
65 Correct 118 ms 13676 KB Output is correct
66 Correct 102 ms 13676 KB Output is correct
67 Correct 96 ms 13676 KB Output is correct
68 Correct 105 ms 13676 KB Output is correct
69 Correct 103 ms 13676 KB Output is correct
70 Correct 110 ms 13928 KB Output is correct
71 Correct 111 ms 13928 KB Output is correct
72 Correct 111 ms 14056 KB Output is correct
73 Correct 100 ms 13928 KB Output is correct
74 Correct 71 ms 13856 KB Output is correct
75 Correct 104 ms 13932 KB Output is correct
76 Correct 88 ms 13552 KB Output is correct
77 Correct 65 ms 13460 KB Output is correct
78 Correct 48 ms 15724 KB Output is correct
79 Correct 54 ms 13804 KB Output is correct
80 Correct 97 ms 13928 KB Output is correct
81 Correct 65 ms 13460 KB Output is correct
82 Correct 48 ms 15724 KB Output is correct
83 Correct 56 ms 13804 KB Output is correct
84 Correct 118 ms 14060 KB Output is correct
85 Correct 118 ms 14060 KB Output is correct
86 Correct 118 ms 14064 KB Output is correct
87 Correct 75 ms 13420 KB Output is correct
88 Correct 157 ms 14064 KB Output is correct