Submission #893336

# Submission time Handle Problem Language Result Execution time Memory
893336 2023-12-27T02:22:25 Z 1075508020060209tc Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
89 ms 26572 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int lowbit(int x){return x&-x;}
int bit[500005];
void upd(int pl,int v){
while(pl<=500000){
    bit[pl]+=v;
    pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl){
    ret=ret+bit[pl];
    pl-=lowbit(pl);
}
return ret;
}
int n;
int ar[500005];
vector<int>e[500005];
void init(){
cin>>n;
for(int i=1;i<=n;i++){
    cin>>ar[i];
    ar[i]=min(ar[i],n);
    e[ar[i]].push_back(i);
}

}

signed main(){
init();
int ans=0;
priority_queue<int>pq;
for(int i=n;i>=1;i--){
    for(int j=0;j<e[i].size();j++){
        pq.push(e[i][j]);
    }
    if(pq.size()==0){cout<<-1<<"\n";return 0;}
    ans+=i-pq.top()+qsum(pq.top());
    upd(pq.top(),1);
    pq.pop();
}
cout<<ans<<"\n";


}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int j=0;j<e[i].size();j++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 6 ms 17132 KB Output is correct
3 Correct 6 ms 16984 KB Output is correct
4 Correct 6 ms 16988 KB Output is correct
5 Correct 6 ms 16988 KB Output is correct
6 Correct 6 ms 17040 KB Output is correct
7 Correct 5 ms 16984 KB Output is correct
8 Correct 5 ms 17036 KB Output is correct
9 Correct 5 ms 16988 KB Output is correct
10 Correct 5 ms 16988 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 6 ms 16988 KB Output is correct
13 Correct 7 ms 17132 KB Output is correct
14 Correct 6 ms 16988 KB Output is correct
15 Correct 5 ms 17036 KB Output is correct
16 Correct 5 ms 16988 KB Output is correct
17 Correct 6 ms 17040 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 6 ms 17132 KB Output is correct
21 Correct 6 ms 16988 KB Output is correct
22 Correct 5 ms 16984 KB Output is correct
23 Correct 6 ms 16988 KB Output is correct
24 Correct 7 ms 16988 KB Output is correct
25 Correct 6 ms 16988 KB Output is correct
26 Correct 6 ms 16988 KB Output is correct
27 Correct 6 ms 16984 KB Output is correct
28 Correct 6 ms 16988 KB Output is correct
29 Correct 7 ms 17176 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 7 ms 16988 KB Output is correct
32 Correct 5 ms 17012 KB Output is correct
33 Correct 5 ms 16988 KB Output is correct
34 Correct 5 ms 16988 KB Output is correct
35 Correct 5 ms 16988 KB Output is correct
36 Correct 6 ms 16988 KB Output is correct
37 Correct 5 ms 16988 KB Output is correct
38 Correct 5 ms 16988 KB Output is correct
39 Correct 6 ms 16988 KB Output is correct
40 Correct 6 ms 16988 KB Output is correct
41 Correct 5 ms 14940 KB Output is correct
42 Correct 6 ms 17160 KB Output is correct
43 Correct 6 ms 14940 KB Output is correct
44 Correct 4 ms 16988 KB Output is correct
45 Correct 4 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 6 ms 17132 KB Output is correct
3 Correct 6 ms 16984 KB Output is correct
4 Correct 6 ms 16988 KB Output is correct
5 Correct 6 ms 16988 KB Output is correct
6 Correct 6 ms 17040 KB Output is correct
7 Correct 5 ms 16984 KB Output is correct
8 Correct 5 ms 17036 KB Output is correct
9 Correct 5 ms 16988 KB Output is correct
10 Correct 5 ms 16988 KB Output is correct
11 Correct 5 ms 16988 KB Output is correct
12 Correct 6 ms 16988 KB Output is correct
13 Correct 7 ms 17132 KB Output is correct
14 Correct 6 ms 16988 KB Output is correct
15 Correct 5 ms 17036 KB Output is correct
16 Correct 5 ms 16988 KB Output is correct
17 Correct 6 ms 17040 KB Output is correct
18 Correct 5 ms 16988 KB Output is correct
19 Correct 6 ms 16988 KB Output is correct
20 Correct 6 ms 17132 KB Output is correct
21 Correct 6 ms 16988 KB Output is correct
22 Correct 5 ms 16984 KB Output is correct
23 Correct 6 ms 16988 KB Output is correct
24 Correct 7 ms 16988 KB Output is correct
25 Correct 6 ms 16988 KB Output is correct
26 Correct 6 ms 16988 KB Output is correct
27 Correct 6 ms 16984 KB Output is correct
28 Correct 6 ms 16988 KB Output is correct
29 Correct 7 ms 17176 KB Output is correct
30 Correct 5 ms 16988 KB Output is correct
31 Correct 7 ms 16988 KB Output is correct
32 Correct 5 ms 17012 KB Output is correct
33 Correct 5 ms 16988 KB Output is correct
34 Correct 5 ms 16988 KB Output is correct
35 Correct 5 ms 16988 KB Output is correct
36 Correct 6 ms 16988 KB Output is correct
37 Correct 5 ms 16988 KB Output is correct
38 Correct 5 ms 16988 KB Output is correct
39 Correct 6 ms 16988 KB Output is correct
40 Correct 6 ms 16988 KB Output is correct
41 Correct 5 ms 14940 KB Output is correct
42 Correct 6 ms 17160 KB Output is correct
43 Correct 6 ms 14940 KB Output is correct
44 Correct 4 ms 16988 KB Output is correct
45 Correct 4 ms 16988 KB Output is correct
46 Correct 87 ms 23740 KB Output is correct
47 Correct 89 ms 23760 KB Output is correct
48 Correct 83 ms 23528 KB Output is correct
49 Correct 86 ms 23520 KB Output is correct
50 Correct 85 ms 23764 KB Output is correct
51 Correct 83 ms 23880 KB Output is correct
52 Correct 73 ms 26500 KB Output is correct
53 Correct 73 ms 26472 KB Output is correct
54 Correct 64 ms 25168 KB Output is correct
55 Correct 64 ms 26448 KB Output is correct
56 Correct 67 ms 26448 KB Output is correct
57 Correct 65 ms 25112 KB Output is correct
58 Correct 73 ms 23228 KB Output is correct
59 Correct 70 ms 23232 KB Output is correct
60 Correct 73 ms 23236 KB Output is correct
61 Correct 68 ms 23376 KB Output is correct
62 Correct 64 ms 24540 KB Output is correct
63 Correct 69 ms 24400 KB Output is correct
64 Correct 82 ms 23128 KB Output is correct
65 Correct 73 ms 23156 KB Output is correct
66 Correct 73 ms 23120 KB Output is correct
67 Correct 80 ms 23124 KB Output is correct
68 Correct 75 ms 23152 KB Output is correct
69 Correct 79 ms 22928 KB Output is correct
70 Correct 83 ms 23300 KB Output is correct
71 Correct 80 ms 23388 KB Output is correct
72 Correct 88 ms 23216 KB Output is correct
73 Correct 80 ms 23184 KB Output is correct
74 Correct 73 ms 23172 KB Output is correct
75 Correct 79 ms 23276 KB Output is correct
76 Correct 71 ms 22868 KB Output is correct
77 Correct 74 ms 22516 KB Output is correct
78 Correct 56 ms 26452 KB Output is correct
79 Correct 62 ms 24400 KB Output is correct
80 Correct 72 ms 23248 KB Output is correct
81 Correct 73 ms 22340 KB Output is correct
82 Correct 73 ms 26572 KB Output is correct
83 Correct 63 ms 24528 KB Output is correct
84 Correct 85 ms 23544 KB Output is correct
85 Correct 85 ms 24940 KB Output is correct
86 Correct 89 ms 23504 KB Output is correct
87 Correct 57 ms 22300 KB Output is correct
88 Correct 84 ms 23512 KB Output is correct