Submission #493547

# Submission time Handle Problem Language Result Execution time Memory
493547 2021-12-12T01:17:57 Z dooompy Cryptography (NOI20_crypto) C++17
51 / 100
115 ms 8132 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int v[300005], p[300005];
ll fact[300005];
int bit[300005];

void add(int p) {
    for (; p < 300005; p += (p&(-p))) {
        bit[p]++;
    }
}

int sum(int p) {
    int s = 0;
    for (; p; p -= (p&(-p))) {
        s += bit[p];
    }
    return s;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        p[i] = v[i];
        if (i == 1) fact[i] = 1;
        else {
            fact[i] = fact[i-1] * i;
            fact[i] %= (ll) (1e9 + 7);
        }
    }
    sort(p+1, p+n+1);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int pos = lower_bound(p+1, p+n+1, v[i]) - p;
        ans += (fact[n-i] * (pos-1-sum(v[i])));
        ans %= (ll)(1e9 + 7);
        add(v[i]);
    }

    cout << (ans + 1) % (ll) ( 1e9 + 7);
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 52 ms 7992 KB Output is correct
3 Correct 53 ms 8004 KB Output is correct
4 Correct 52 ms 8016 KB Output is correct
5 Correct 51 ms 8084 KB Output is correct
6 Correct 52 ms 8060 KB Output is correct
7 Correct 56 ms 8072 KB Output is correct
8 Correct 60 ms 8084 KB Output is correct
9 Correct 53 ms 8004 KB Output is correct
10 Correct 54 ms 8056 KB Output is correct
11 Correct 52 ms 8004 KB Output is correct
12 Correct 54 ms 8028 KB Output is correct
13 Correct 56 ms 8048 KB Output is correct
14 Correct 61 ms 7984 KB Output is correct
15 Correct 50 ms 8092 KB Output is correct
16 Correct 50 ms 8092 KB Output is correct
17 Correct 52 ms 8008 KB Output is correct
18 Correct 52 ms 8008 KB Output is correct
19 Correct 54 ms 8076 KB Output is correct
20 Correct 55 ms 8080 KB Output is correct
21 Correct 60 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 52 ms 7992 KB Output is correct
3 Correct 53 ms 8004 KB Output is correct
4 Correct 52 ms 8016 KB Output is correct
5 Correct 51 ms 8084 KB Output is correct
6 Correct 52 ms 8060 KB Output is correct
7 Correct 56 ms 8072 KB Output is correct
8 Correct 60 ms 8084 KB Output is correct
9 Correct 53 ms 8004 KB Output is correct
10 Correct 54 ms 8056 KB Output is correct
11 Correct 52 ms 8004 KB Output is correct
12 Correct 54 ms 8028 KB Output is correct
13 Correct 56 ms 8048 KB Output is correct
14 Correct 61 ms 7984 KB Output is correct
15 Correct 50 ms 8092 KB Output is correct
16 Correct 50 ms 8092 KB Output is correct
17 Correct 52 ms 8008 KB Output is correct
18 Correct 52 ms 8008 KB Output is correct
19 Correct 54 ms 8076 KB Output is correct
20 Correct 55 ms 8080 KB Output is correct
21 Correct 60 ms 8100 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 0 ms 332 KB Output is correct
45 Correct 99 ms 8088 KB Output is correct
46 Correct 111 ms 8088 KB Output is correct
47 Correct 100 ms 8004 KB Output is correct
48 Correct 103 ms 8132 KB Output is correct
49 Correct 99 ms 8072 KB Output is correct
50 Correct 103 ms 8128 KB Output is correct
51 Correct 100 ms 8112 KB Output is correct
52 Correct 103 ms 8108 KB Output is correct
53 Correct 115 ms 8092 KB Output is correct
54 Correct 101 ms 8108 KB Output is correct
55 Correct 106 ms 8060 KB Output is correct
56 Correct 99 ms 8028 KB Output is correct
57 Correct 101 ms 8092 KB Output is correct
58 Correct 0 ms 316 KB Output is correct
59 Correct 102 ms 8132 KB Output is correct
60 Correct 102 ms 8104 KB Output is correct
61 Correct 100 ms 8032 KB Output is correct
62 Correct 100 ms 8096 KB Output is correct
63 Correct 99 ms 8016 KB Output is correct
64 Correct 101 ms 8004 KB Output is correct
65 Correct 100 ms 8104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -