Submission #362704

# Submission time Handle Problem Language Result Execution time Memory
362704 2021-02-04T07:19:55 Z alextodoran Exercise Deadlines (CCO20_day1problem2) C++17
25 / 25
232 ms 13548 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;

int n;

int d[N_MAX];

int p[N_MAX];

set <int> s;

int BIT[N_MAX];

void update (int pos)
{
    for(int i = pos; i >= 1; i -= i & -i)
        BIT[i]++;
}

int query (int pos)
{
    int ans = 0;
    for(int i = pos; i <= n; i += i & -i)
        ans += BIT[i];
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> d[i];
    for(int i = 1; i <= n; i++)
        s.insert(i);
    for(int i = n; i >= 1; i--)
    {
        set <int> :: iterator it = s.upper_bound(d[i]);
        if(it == s.begin())
        {
            cout << "-1\n";
            return 0;
        }
        it--;
        p[i] = *it;
        s.erase(it);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans += query(p[i]);
        update(p[i]);
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 620 KB Output is correct
38 Correct 2 ms 640 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 620 KB Output is correct
42 Correct 2 ms 620 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 2 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 620 KB Output is correct
38 Correct 2 ms 640 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 620 KB Output is correct
42 Correct 2 ms 620 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 116 ms 13420 KB Output is correct
47 Correct 116 ms 13420 KB Output is correct
48 Correct 92 ms 13420 KB Output is correct
49 Correct 114 ms 13548 KB Output is correct
50 Correct 129 ms 13548 KB Output is correct
51 Correct 115 ms 13420 KB Output is correct
52 Correct 188 ms 13292 KB Output is correct
53 Correct 188 ms 13548 KB Output is correct
54 Correct 134 ms 13420 KB Output is correct
55 Correct 94 ms 13404 KB Output is correct
56 Correct 137 ms 13292 KB Output is correct
57 Correct 138 ms 13292 KB Output is correct
58 Correct 186 ms 13292 KB Output is correct
59 Correct 232 ms 13292 KB Output is correct
60 Correct 163 ms 13420 KB Output is correct
61 Correct 135 ms 13292 KB Output is correct
62 Correct 100 ms 13292 KB Output is correct
63 Correct 145 ms 13548 KB Output is correct
64 Correct 191 ms 13292 KB Output is correct
65 Correct 173 ms 13500 KB Output is correct
66 Correct 141 ms 13292 KB Output is correct
67 Correct 125 ms 13420 KB Output is correct
68 Correct 152 ms 13292 KB Output is correct
69 Correct 171 ms 13312 KB Output is correct
70 Correct 140 ms 13420 KB Output is correct
71 Correct 155 ms 13548 KB Output is correct
72 Correct 160 ms 13420 KB Output is correct
73 Correct 115 ms 13420 KB Output is correct
74 Correct 105 ms 13420 KB Output is correct
75 Correct 142 ms 13420 KB Output is correct
76 Correct 119 ms 12652 KB Output is correct
77 Correct 81 ms 13420 KB Output is correct
78 Correct 106 ms 13356 KB Output is correct
79 Correct 88 ms 13420 KB Output is correct
80 Correct 114 ms 12652 KB Output is correct
81 Correct 86 ms 13484 KB Output is correct
82 Correct 93 ms 13292 KB Output is correct
83 Correct 94 ms 13292 KB Output is correct
84 Correct 142 ms 13488 KB Output is correct
85 Correct 151 ms 13420 KB Output is correct
86 Correct 147 ms 13388 KB Output is correct
87 Correct 134 ms 12696 KB Output is correct
88 Correct 138 ms 13408 KB Output is correct