Submission #305557

# Submission time Handle Problem Language Result Execution time Memory
305557 2020-09-23T13:59:33 Z nickmet2004 Exercise Deadlines (CCO20_day1problem2) C++11
17 / 25
123 ms 10484 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int n , d[N];
int F[N];
vector<int> E[N];

void upd(int i , int v){
    for(; i <=n; i += i & -i) F[i]+=v;
}
int get(int i){
    int sum = 0;
    for(; i; i -= i & -i) sum += F[i]; return sum;
}
int main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> d[i] ,E[d[i]].emplace_back(i);
    sort(d+ 1 , d + n + 1); for(int i=1; i<= n; ++i) if(d[i] < i){cout << -1; return 0;}
    for(int i = 1; i <= n; ++i) upd(i , 1);
    priority_queue<int> pq;
    int ans =0;
    for(int i = n; i; --i){
        for(int x : E[i]) pq.push(x);
        int a= pq.top(); pq.pop();
        upd(n - a + 1 ,-1);
        ans += get(n - a + 1);
    }cout << ans;

}

Compilation message

Main.cpp: In function 'int get(int)':
Main.cpp:14:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |     for(; i; i -= i & -i) sum += F[i]; return sum;
      |     ^~~
Main.cpp:14:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |     for(; i; i -= i & -i) sum += F[i]; return sum;
      |                                        ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 5 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 6 ms 5120 KB Output is correct
29 Correct 5 ms 5120 KB Output is correct
30 Correct 5 ms 5120 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 6 ms 5120 KB Output is correct
41 Correct 5 ms 5120 KB Output is correct
42 Correct 5 ms 5120 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 5 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 6 ms 5120 KB Output is correct
29 Correct 5 ms 5120 KB Output is correct
30 Correct 5 ms 5120 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 6 ms 5120 KB Output is correct
41 Correct 5 ms 5120 KB Output is correct
42 Correct 5 ms 5120 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Incorrect 123 ms 10484 KB Output isn't correct
47 Halted 0 ms 0 KB -