Submission #293542

# Submission time Handle Problem Language Result Execution time Memory
293542 2020-09-08T07:38:51 Z toloraia Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
118 ms 14976 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define int long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")

#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 200005;

int n, F[N];

void upd (int x){
    for (; x <= n; x += x & -x)
        F[x]++;
}

int dat (int x){
    int ans = 0;
    for (; x > 0; x &= x-1)
        ans += F[x];
    return ans;
}

int ans;
int a[N];
vector < int > V[N];

priority_queue < int > Q;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = n - a[i] + 1;
    }
    reverse (a+1, a+n+1);
    for (int i = 1; i <= n; i++)
        V[a[i]].pb (i);
    for (int i = 1; i <= n; i++){
        for (int x : V[i])
            Q.push (-x);
        if (Q.size() == 0){
            cout << -1 << endl;
            return 0;
        }
        int x = -Q.top();
        Q.pop();
        ans += dat (n) - dat (x);
        upd (x);
    }
    cout << ans << endl;
}

Compilation message

Main.cpp:19:1: warning: "/*" within comment [-Wcomment]
   19 | /*
      |  
Main.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main()
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5232 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 5 ms 5248 KB Output is correct
4 Correct 5 ms 5248 KB Output is correct
5 Correct 5 ms 5376 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 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 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 5 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 5 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 5 ms 5248 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 5 ms 5248 KB Output is correct
23 Correct 5 ms 5248 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 6 ms 5248 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 5 ms 5376 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 5 ms 5248 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5280 KB Output is correct
41 Correct 4 ms 5248 KB Output is correct
42 Correct 5 ms 5280 KB Output is correct
43 Correct 4 ms 5248 KB Output is correct
44 Correct 3 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 5232 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Correct 5 ms 5248 KB Output is correct
4 Correct 5 ms 5248 KB Output is correct
5 Correct 5 ms 5376 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 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 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 5 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 5 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 5 ms 5248 KB Output is correct
21 Correct 5 ms 5248 KB Output is correct
22 Correct 5 ms 5248 KB Output is correct
23 Correct 5 ms 5248 KB Output is correct
24 Correct 6 ms 5248 KB Output is correct
25 Correct 6 ms 5248 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 5 ms 5376 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 5 ms 5248 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 5 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5280 KB Output is correct
41 Correct 4 ms 5248 KB Output is correct
42 Correct 5 ms 5280 KB Output is correct
43 Correct 4 ms 5248 KB Output is correct
44 Correct 3 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Correct 110 ms 13280 KB Output is correct
47 Correct 99 ms 13160 KB Output is correct
48 Correct 86 ms 13144 KB Output is correct
49 Correct 86 ms 13164 KB Output is correct
50 Correct 87 ms 13160 KB Output is correct
51 Correct 87 ms 13228 KB Output is correct
52 Correct 107 ms 14968 KB Output is correct
53 Correct 91 ms 14968 KB Output is correct
54 Correct 80 ms 14968 KB Output is correct
55 Correct 50 ms 14968 KB Output is correct
56 Correct 82 ms 14968 KB Output is correct
57 Correct 73 ms 14968 KB Output is correct
58 Correct 117 ms 12920 KB Output is correct
59 Correct 92 ms 12920 KB Output is correct
60 Correct 86 ms 12920 KB Output is correct
61 Correct 77 ms 12920 KB Output is correct
62 Correct 56 ms 12920 KB Output is correct
63 Correct 72 ms 12920 KB Output is correct
64 Correct 93 ms 13048 KB Output is correct
65 Correct 99 ms 12920 KB Output is correct
66 Correct 86 ms 12920 KB Output is correct
67 Correct 74 ms 12920 KB Output is correct
68 Correct 86 ms 12968 KB Output is correct
69 Correct 89 ms 12920 KB Output is correct
70 Correct 96 ms 13044 KB Output is correct
71 Correct 115 ms 12916 KB Output is correct
72 Correct 91 ms 12916 KB Output is correct
73 Correct 88 ms 13044 KB Output is correct
74 Correct 66 ms 12980 KB Output is correct
75 Correct 115 ms 12916 KB Output is correct
76 Correct 66 ms 12664 KB Output is correct
77 Correct 62 ms 12188 KB Output is correct
78 Correct 44 ms 14968 KB Output is correct
79 Correct 56 ms 13048 KB Output is correct
80 Correct 95 ms 13040 KB Output is correct
81 Correct 63 ms 12188 KB Output is correct
82 Correct 42 ms 14976 KB Output is correct
83 Correct 48 ms 12920 KB Output is correct
84 Correct 118 ms 13168 KB Output is correct
85 Correct 101 ms 13172 KB Output is correct
86 Correct 100 ms 13172 KB Output is correct
87 Correct 61 ms 11128 KB Output is correct
88 Correct 102 ms 13168 KB Output is correct