답안 #766994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766994 2023-06-26T09:59:58 Z Tenis0206 Exercise Deadlines (CCO20_day1problem2) C++11
25 / 25
110 ms 13432 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 2e5;

int n;
int v[nmax + 5];

int poz[nmax + 5];

set<int,greater<int>> s;

int aib[nmax + 5];

int ub(int x)
{
    return (x & (-x));
}

void update(int poz, int val)
{
    for(int i=poz;i<=n;i+=ub(i))
    {
        aib[i] += val;
    }
}

int query(int qa, int qb)
{
    int rez = 0;
    for(int i=qb;i>=1;i-=ub(i))
    {
        rez += aib[i];
    }
    for(int i=qa-1;i>=1;i-=ub(i))
    {
        rez -= aib[i];
    }
    return rez;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        s.insert(i);
    }
    for(int i=n;i>=1;i--)
    {
        auto it = s.lower_bound(v[i]);
        if(it==s.end())
        {
            cout<<-1<<'\n';
            return 0;
        }
        poz[i] = *it;
        s.erase(it);
    }
    long long rez = 0;
    for(int i=1;i<=n;i++)
    {
        rez += query(poz[i], n);
        update(poz[i],+1);
    }
    cout<<rez<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 720 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 572 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 720 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 572 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 76 ms 12036 KB Output is correct
47 Correct 75 ms 13264 KB Output is correct
48 Correct 65 ms 13360 KB Output is correct
49 Correct 69 ms 13340 KB Output is correct
50 Correct 80 ms 13300 KB Output is correct
51 Correct 75 ms 13380 KB Output is correct
52 Correct 101 ms 13248 KB Output is correct
53 Correct 109 ms 13228 KB Output is correct
54 Correct 88 ms 13308 KB Output is correct
55 Correct 68 ms 13276 KB Output is correct
56 Correct 92 ms 13288 KB Output is correct
57 Correct 88 ms 13252 KB Output is correct
58 Correct 101 ms 13252 KB Output is correct
59 Correct 110 ms 13224 KB Output is correct
60 Correct 103 ms 13192 KB Output is correct
61 Correct 82 ms 13260 KB Output is correct
62 Correct 68 ms 13168 KB Output is correct
63 Correct 86 ms 13232 KB Output is correct
64 Correct 105 ms 13204 KB Output is correct
65 Correct 100 ms 13224 KB Output is correct
66 Correct 101 ms 13264 KB Output is correct
67 Correct 77 ms 13388 KB Output is correct
68 Correct 88 ms 13280 KB Output is correct
69 Correct 98 ms 13260 KB Output is correct
70 Correct 87 ms 13288 KB Output is correct
71 Correct 106 ms 13432 KB Output is correct
72 Correct 88 ms 13204 KB Output is correct
73 Correct 74 ms 13236 KB Output is correct
74 Correct 67 ms 13324 KB Output is correct
75 Correct 103 ms 13260 KB Output is correct
76 Correct 73 ms 12576 KB Output is correct
77 Correct 61 ms 13312 KB Output is correct
78 Correct 59 ms 13196 KB Output is correct
79 Correct 63 ms 13260 KB Output is correct
80 Correct 72 ms 12528 KB Output is correct
81 Correct 71 ms 13392 KB Output is correct
82 Correct 60 ms 13276 KB Output is correct
83 Correct 65 ms 13192 KB Output is correct
84 Correct 87 ms 13248 KB Output is correct
85 Correct 86 ms 13272 KB Output is correct
86 Correct 88 ms 13320 KB Output is correct
87 Correct 83 ms 12592 KB Output is correct
88 Correct 98 ms 13248 KB Output is correct