Submission #330583

# Submission time Handle Problem Language Result Execution time Memory
330583 2020-11-25T20:37:28 Z jungsnow Cryptography (NOI20_crypto) C++14
100 / 100
619 ms 35180 KB
#include<bits/stdc++.h>

using namespace std;

const int maxn = 300100, mod = 1e9 + 7;

int add(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int N, A[maxn], fac[maxn];

template<typename T>
struct fenwick {
    T bit[maxn];
    fenwick() {
        fill(bit, bit + maxn, T(0));
    }
    void upd(int x, T val) {
        for (; x < maxn; x += x & -x)
            bit[x] += val;
    }
    T get(int x) {
        T res = 0;
        for (; x; x -= x & -x)
            res += bit[x];
        return res;
    }
};

fenwick<int> T1;

int main() {
//    freopen("cc.inp", "r", stdin);
//    freopen("cc.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    fac[0] = 1;
    set<int> s;
    map<int, int> mp;
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
        s.insert(A[i]);
        fac[i] = mul(fac[i - 1], i);
    }
    int cur = 0;
    for (auto it = s.begin(); it != s.end(); ++it) {
        mp[*it] = ++cur;
    }
    int Ans = 0;
    for (int i = N; i >= 1; --i) {
        A[i] = mp[A[i]];
        Ans = add(Ans, mul(T1.get(A[i] - 1), fac[N - i]));
        T1.upd(A[i], 1);
    }
    cout << add(Ans, 1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 1 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 1 ms 1516 KB Output is correct
3 Correct 1 ms 1516 KB Output is correct
4 Correct 1 ms 1516 KB Output is correct
5 Correct 1 ms 1516 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1516 KB Output is correct
8 Correct 1 ms 1516 KB Output is correct
9 Correct 1 ms 1516 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
11 Correct 1 ms 1516 KB Output is correct
12 Correct 1 ms 1516 KB Output is correct
13 Correct 1 ms 1516 KB Output is correct
14 Correct 1 ms 1516 KB Output is correct
15 Correct 1 ms 1516 KB Output is correct
16 Correct 1 ms 1516 KB Output is correct
17 Correct 1 ms 1516 KB Output is correct
18 Correct 1 ms 1516 KB Output is correct
19 Correct 1 ms 1516 KB Output is correct
20 Correct 1 ms 1516 KB Output is correct
21 Correct 1 ms 1516 KB Output is correct
22 Correct 1 ms 1516 KB Output is correct
23 Correct 1 ms 1516 KB Output is correct
24 Correct 1 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 226 ms 35052 KB Output is correct
3 Correct 225 ms 35180 KB Output is correct
4 Correct 229 ms 34924 KB Output is correct
5 Correct 224 ms 35052 KB Output is correct
6 Correct 225 ms 35052 KB Output is correct
7 Correct 228 ms 34924 KB Output is correct
8 Correct 223 ms 34924 KB Output is correct
9 Correct 222 ms 35052 KB Output is correct
10 Correct 223 ms 35052 KB Output is correct
11 Correct 220 ms 34924 KB Output is correct
12 Correct 224 ms 35124 KB Output is correct
13 Correct 221 ms 34924 KB Output is correct
14 Correct 225 ms 34924 KB Output is correct
15 Correct 228 ms 35052 KB Output is correct
16 Correct 222 ms 34924 KB Output is correct
17 Correct 224 ms 34924 KB Output is correct
18 Correct 228 ms 34956 KB Output is correct
19 Correct 224 ms 35004 KB Output is correct
20 Correct 226 ms 35048 KB Output is correct
21 Correct 221 ms 35052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 217 ms 34028 KB Output is correct
3 Correct 220 ms 34156 KB Output is correct
4 Correct 217 ms 34156 KB Output is correct
5 Correct 216 ms 34028 KB Output is correct
6 Correct 221 ms 34028 KB Output is correct
7 Correct 217 ms 34028 KB Output is correct
8 Correct 215 ms 34028 KB Output is correct
9 Correct 221 ms 34028 KB Output is correct
10 Correct 215 ms 34056 KB Output is correct
11 Correct 218 ms 34156 KB Output is correct
12 Correct 222 ms 34028 KB Output is correct
13 Correct 215 ms 34028 KB Output is correct
14 Correct 218 ms 34028 KB Output is correct
15 Correct 215 ms 34028 KB Output is correct
16 Correct 221 ms 34028 KB Output is correct
17 Correct 218 ms 34156 KB Output is correct
18 Correct 218 ms 34160 KB Output is correct
19 Correct 219 ms 34028 KB Output is correct
20 Correct 219 ms 34120 KB Output is correct
21 Correct 218 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 3 ms 1900 KB Output is correct
3 Correct 3 ms 1900 KB Output is correct
4 Correct 3 ms 1900 KB Output is correct
5 Correct 3 ms 1900 KB Output is correct
6 Correct 3 ms 1900 KB Output is correct
7 Correct 3 ms 1900 KB Output is correct
8 Correct 3 ms 1900 KB Output is correct
9 Correct 3 ms 1900 KB Output is correct
10 Correct 3 ms 1900 KB Output is correct
11 Correct 3 ms 1900 KB Output is correct
12 Correct 3 ms 1900 KB Output is correct
13 Correct 3 ms 1900 KB Output is correct
14 Correct 3 ms 1900 KB Output is correct
15 Correct 1 ms 1516 KB Output is correct
16 Correct 3 ms 1900 KB Output is correct
17 Correct 3 ms 1900 KB Output is correct
18 Correct 3 ms 1900 KB Output is correct
19 Correct 3 ms 1900 KB Output is correct
20 Correct 3 ms 1900 KB Output is correct
21 Correct 3 ms 1900 KB Output is correct
22 Correct 3 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 1 ms 1516 KB Output is correct
3 Correct 1 ms 1516 KB Output is correct
4 Correct 1 ms 1516 KB Output is correct
5 Correct 1 ms 1516 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1516 KB Output is correct
8 Correct 1 ms 1516 KB Output is correct
9 Correct 1 ms 1516 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
11 Correct 1 ms 1516 KB Output is correct
12 Correct 1 ms 1516 KB Output is correct
13 Correct 1 ms 1516 KB Output is correct
14 Correct 1 ms 1516 KB Output is correct
15 Correct 1 ms 1516 KB Output is correct
16 Correct 1 ms 1516 KB Output is correct
17 Correct 1 ms 1516 KB Output is correct
18 Correct 1 ms 1516 KB Output is correct
19 Correct 1 ms 1516 KB Output is correct
20 Correct 1 ms 1516 KB Output is correct
21 Correct 1 ms 1516 KB Output is correct
22 Correct 1 ms 1516 KB Output is correct
23 Correct 1 ms 1516 KB Output is correct
24 Correct 1 ms 1536 KB Output is correct
25 Correct 1 ms 1516 KB Output is correct
26 Correct 3 ms 1900 KB Output is correct
27 Correct 3 ms 1900 KB Output is correct
28 Correct 3 ms 1900 KB Output is correct
29 Correct 3 ms 1900 KB Output is correct
30 Correct 3 ms 1900 KB Output is correct
31 Correct 3 ms 1900 KB Output is correct
32 Correct 3 ms 1900 KB Output is correct
33 Correct 3 ms 1900 KB Output is correct
34 Correct 3 ms 1900 KB Output is correct
35 Correct 3 ms 1900 KB Output is correct
36 Correct 3 ms 1900 KB Output is correct
37 Correct 3 ms 1900 KB Output is correct
38 Correct 3 ms 1900 KB Output is correct
39 Correct 1 ms 1516 KB Output is correct
40 Correct 3 ms 1900 KB Output is correct
41 Correct 3 ms 1900 KB Output is correct
42 Correct 3 ms 1900 KB Output is correct
43 Correct 3 ms 1900 KB Output is correct
44 Correct 3 ms 1900 KB Output is correct
45 Correct 3 ms 1900 KB Output is correct
46 Correct 3 ms 1900 KB Output is correct
47 Correct 1 ms 1516 KB Output is correct
48 Correct 3 ms 1900 KB Output is correct
49 Correct 3 ms 1900 KB Output is correct
50 Correct 3 ms 1900 KB Output is correct
51 Correct 3 ms 1900 KB Output is correct
52 Correct 3 ms 1900 KB Output is correct
53 Correct 3 ms 1900 KB Output is correct
54 Correct 3 ms 1900 KB Output is correct
55 Correct 3 ms 1900 KB Output is correct
56 Correct 3 ms 1900 KB Output is correct
57 Correct 3 ms 1900 KB Output is correct
58 Correct 3 ms 1900 KB Output is correct
59 Correct 3 ms 1900 KB Output is correct
60 Correct 3 ms 1900 KB Output is correct
61 Correct 1 ms 1516 KB Output is correct
62 Correct 4 ms 1900 KB Output is correct
63 Correct 4 ms 1900 KB Output is correct
64 Correct 3 ms 1900 KB Output is correct
65 Correct 3 ms 1900 KB Output is correct
66 Correct 3 ms 1900 KB Output is correct
67 Correct 3 ms 1900 KB Output is correct
68 Correct 3 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 217 ms 34028 KB Output is correct
3 Correct 220 ms 34156 KB Output is correct
4 Correct 217 ms 34156 KB Output is correct
5 Correct 216 ms 34028 KB Output is correct
6 Correct 221 ms 34028 KB Output is correct
7 Correct 217 ms 34028 KB Output is correct
8 Correct 215 ms 34028 KB Output is correct
9 Correct 221 ms 34028 KB Output is correct
10 Correct 215 ms 34056 KB Output is correct
11 Correct 218 ms 34156 KB Output is correct
12 Correct 222 ms 34028 KB Output is correct
13 Correct 215 ms 34028 KB Output is correct
14 Correct 218 ms 34028 KB Output is correct
15 Correct 215 ms 34028 KB Output is correct
16 Correct 221 ms 34028 KB Output is correct
17 Correct 218 ms 34156 KB Output is correct
18 Correct 218 ms 34160 KB Output is correct
19 Correct 219 ms 34028 KB Output is correct
20 Correct 219 ms 34120 KB Output is correct
21 Correct 218 ms 34028 KB Output is correct
22 Correct 1 ms 1516 KB Output is correct
23 Correct 3 ms 1900 KB Output is correct
24 Correct 3 ms 1900 KB Output is correct
25 Correct 3 ms 1900 KB Output is correct
26 Correct 3 ms 1900 KB Output is correct
27 Correct 3 ms 1900 KB Output is correct
28 Correct 3 ms 1900 KB Output is correct
29 Correct 3 ms 1900 KB Output is correct
30 Correct 3 ms 1900 KB Output is correct
31 Correct 3 ms 1900 KB Output is correct
32 Correct 3 ms 1900 KB Output is correct
33 Correct 3 ms 1900 KB Output is correct
34 Correct 3 ms 1900 KB Output is correct
35 Correct 3 ms 1900 KB Output is correct
36 Correct 1 ms 1516 KB Output is correct
37 Correct 3 ms 1900 KB Output is correct
38 Correct 3 ms 1900 KB Output is correct
39 Correct 3 ms 1900 KB Output is correct
40 Correct 3 ms 1900 KB Output is correct
41 Correct 3 ms 1900 KB Output is correct
42 Correct 3 ms 1900 KB Output is correct
43 Correct 3 ms 1900 KB Output is correct
44 Correct 1 ms 1516 KB Output is correct
45 Correct 608 ms 34192 KB Output is correct
46 Correct 608 ms 34112 KB Output is correct
47 Correct 584 ms 34172 KB Output is correct
48 Correct 580 ms 34028 KB Output is correct
49 Correct 586 ms 34028 KB Output is correct
50 Correct 586 ms 34156 KB Output is correct
51 Correct 573 ms 34284 KB Output is correct
52 Correct 575 ms 34028 KB Output is correct
53 Correct 566 ms 34028 KB Output is correct
54 Correct 572 ms 34156 KB Output is correct
55 Correct 571 ms 34028 KB Output is correct
56 Correct 596 ms 34028 KB Output is correct
57 Correct 577 ms 34124 KB Output is correct
58 Correct 1 ms 1516 KB Output is correct
59 Correct 585 ms 34156 KB Output is correct
60 Correct 588 ms 34156 KB Output is correct
61 Correct 589 ms 34156 KB Output is correct
62 Correct 585 ms 34028 KB Output is correct
63 Correct 577 ms 33968 KB Output is correct
64 Correct 615 ms 34028 KB Output is correct
65 Correct 616 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1516 KB Output is correct
2 Correct 1 ms 1516 KB Output is correct
3 Correct 1 ms 1516 KB Output is correct
4 Correct 1 ms 1516 KB Output is correct
5 Correct 1 ms 1516 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1516 KB Output is correct
8 Correct 1 ms 1516 KB Output is correct
9 Correct 1 ms 1516 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
11 Correct 1 ms 1516 KB Output is correct
12 Correct 1 ms 1516 KB Output is correct
13 Correct 1 ms 1516 KB Output is correct
14 Correct 1 ms 1516 KB Output is correct
15 Correct 1 ms 1516 KB Output is correct
16 Correct 1 ms 1516 KB Output is correct
17 Correct 1 ms 1516 KB Output is correct
18 Correct 1 ms 1516 KB Output is correct
19 Correct 1 ms 1516 KB Output is correct
20 Correct 1 ms 1516 KB Output is correct
21 Correct 1 ms 1516 KB Output is correct
22 Correct 1 ms 1516 KB Output is correct
23 Correct 1 ms 1516 KB Output is correct
24 Correct 1 ms 1536 KB Output is correct
25 Correct 2 ms 1516 KB Output is correct
26 Correct 226 ms 35052 KB Output is correct
27 Correct 225 ms 35180 KB Output is correct
28 Correct 229 ms 34924 KB Output is correct
29 Correct 224 ms 35052 KB Output is correct
30 Correct 225 ms 35052 KB Output is correct
31 Correct 228 ms 34924 KB Output is correct
32 Correct 223 ms 34924 KB Output is correct
33 Correct 222 ms 35052 KB Output is correct
34 Correct 223 ms 35052 KB Output is correct
35 Correct 220 ms 34924 KB Output is correct
36 Correct 224 ms 35124 KB Output is correct
37 Correct 221 ms 34924 KB Output is correct
38 Correct 225 ms 34924 KB Output is correct
39 Correct 228 ms 35052 KB Output is correct
40 Correct 222 ms 34924 KB Output is correct
41 Correct 224 ms 34924 KB Output is correct
42 Correct 228 ms 34956 KB Output is correct
43 Correct 224 ms 35004 KB Output is correct
44 Correct 226 ms 35048 KB Output is correct
45 Correct 221 ms 35052 KB Output is correct
46 Correct 1 ms 1516 KB Output is correct
47 Correct 217 ms 34028 KB Output is correct
48 Correct 220 ms 34156 KB Output is correct
49 Correct 217 ms 34156 KB Output is correct
50 Correct 216 ms 34028 KB Output is correct
51 Correct 221 ms 34028 KB Output is correct
52 Correct 217 ms 34028 KB Output is correct
53 Correct 215 ms 34028 KB Output is correct
54 Correct 221 ms 34028 KB Output is correct
55 Correct 215 ms 34056 KB Output is correct
56 Correct 218 ms 34156 KB Output is correct
57 Correct 222 ms 34028 KB Output is correct
58 Correct 215 ms 34028 KB Output is correct
59 Correct 218 ms 34028 KB Output is correct
60 Correct 215 ms 34028 KB Output is correct
61 Correct 221 ms 34028 KB Output is correct
62 Correct 218 ms 34156 KB Output is correct
63 Correct 218 ms 34160 KB Output is correct
64 Correct 219 ms 34028 KB Output is correct
65 Correct 219 ms 34120 KB Output is correct
66 Correct 218 ms 34028 KB Output is correct
67 Correct 1 ms 1516 KB Output is correct
68 Correct 3 ms 1900 KB Output is correct
69 Correct 3 ms 1900 KB Output is correct
70 Correct 3 ms 1900 KB Output is correct
71 Correct 3 ms 1900 KB Output is correct
72 Correct 3 ms 1900 KB Output is correct
73 Correct 3 ms 1900 KB Output is correct
74 Correct 3 ms 1900 KB Output is correct
75 Correct 3 ms 1900 KB Output is correct
76 Correct 3 ms 1900 KB Output is correct
77 Correct 3 ms 1900 KB Output is correct
78 Correct 3 ms 1900 KB Output is correct
79 Correct 3 ms 1900 KB Output is correct
80 Correct 3 ms 1900 KB Output is correct
81 Correct 1 ms 1516 KB Output is correct
82 Correct 3 ms 1900 KB Output is correct
83 Correct 3 ms 1900 KB Output is correct
84 Correct 3 ms 1900 KB Output is correct
85 Correct 3 ms 1900 KB Output is correct
86 Correct 3 ms 1900 KB Output is correct
87 Correct 3 ms 1900 KB Output is correct
88 Correct 3 ms 1900 KB Output is correct
89 Correct 1 ms 1516 KB Output is correct
90 Correct 3 ms 1900 KB Output is correct
91 Correct 3 ms 1900 KB Output is correct
92 Correct 3 ms 1900 KB Output is correct
93 Correct 3 ms 1900 KB Output is correct
94 Correct 3 ms 1900 KB Output is correct
95 Correct 3 ms 1900 KB Output is correct
96 Correct 3 ms 1900 KB Output is correct
97 Correct 3 ms 1900 KB Output is correct
98 Correct 3 ms 1900 KB Output is correct
99 Correct 3 ms 1900 KB Output is correct
100 Correct 3 ms 1900 KB Output is correct
101 Correct 3 ms 1900 KB Output is correct
102 Correct 3 ms 1900 KB Output is correct
103 Correct 1 ms 1516 KB Output is correct
104 Correct 4 ms 1900 KB Output is correct
105 Correct 4 ms 1900 KB Output is correct
106 Correct 3 ms 1900 KB Output is correct
107 Correct 3 ms 1900 KB Output is correct
108 Correct 3 ms 1900 KB Output is correct
109 Correct 3 ms 1900 KB Output is correct
110 Correct 3 ms 1900 KB Output is correct
111 Correct 1 ms 1516 KB Output is correct
112 Correct 608 ms 34192 KB Output is correct
113 Correct 608 ms 34112 KB Output is correct
114 Correct 584 ms 34172 KB Output is correct
115 Correct 580 ms 34028 KB Output is correct
116 Correct 586 ms 34028 KB Output is correct
117 Correct 586 ms 34156 KB Output is correct
118 Correct 573 ms 34284 KB Output is correct
119 Correct 575 ms 34028 KB Output is correct
120 Correct 566 ms 34028 KB Output is correct
121 Correct 572 ms 34156 KB Output is correct
122 Correct 571 ms 34028 KB Output is correct
123 Correct 596 ms 34028 KB Output is correct
124 Correct 577 ms 34124 KB Output is correct
125 Correct 1 ms 1516 KB Output is correct
126 Correct 585 ms 34156 KB Output is correct
127 Correct 588 ms 34156 KB Output is correct
128 Correct 589 ms 34156 KB Output is correct
129 Correct 585 ms 34028 KB Output is correct
130 Correct 577 ms 33968 KB Output is correct
131 Correct 615 ms 34028 KB Output is correct
132 Correct 616 ms 34028 KB Output is correct
133 Correct 1 ms 1516 KB Output is correct
134 Correct 609 ms 35112 KB Output is correct
135 Correct 610 ms 34904 KB Output is correct
136 Correct 606 ms 35180 KB Output is correct
137 Correct 613 ms 35052 KB Output is correct
138 Correct 614 ms 35052 KB Output is correct
139 Correct 594 ms 34924 KB Output is correct
140 Correct 601 ms 34924 KB Output is correct
141 Correct 594 ms 35052 KB Output is correct
142 Correct 601 ms 35052 KB Output is correct
143 Correct 605 ms 35052 KB Output is correct
144 Correct 610 ms 35180 KB Output is correct
145 Correct 619 ms 35052 KB Output is correct
146 Correct 613 ms 35052 KB Output is correct
147 Correct 1 ms 1644 KB Output is correct
148 Correct 585 ms 34924 KB Output is correct
149 Correct 596 ms 34924 KB Output is correct
150 Correct 596 ms 35180 KB Output is correct
151 Correct 594 ms 35052 KB Output is correct
152 Correct 584 ms 35072 KB Output is correct
153 Correct 583 ms 34944 KB Output is correct
154 Correct 599 ms 35060 KB Output is correct