Submission #873925

# Submission time Handle Problem Language Result Execution time Memory
873925 2023-11-16T02:47:48 Z noiaint Cryptography (NOI20_crypto) C++17
100 / 100
118 ms 15184 KB
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()

#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define popcount __builtin_popcountll

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
    return l + rd() % (r - l + 1);
}

const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int inf = 1e9; // INT_MAX;
const long long llinf = 1e18; // LLONG_MAX;

template<class X, class Y>
bool minimize(X &a, Y b) {
    return a > b ? (a = b, true) : false;
}

template<class X, class Y>
bool maximize(X &a, Y b) {
    return a < b ? (a = b, true) : false;
}

template<class X, class Y>
bool add(X &a, Y b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return true;
}

int n;
int a[N];
int fac[N];
vector<int> temp;

int bit[N];
void update(int u, int c) {
    for (; u <= n; u += u & (-u)) bit[u] += c;
}
int get(int u) {
    int res = 0;
    for (; u > 0; u -= u & (-u)) res += bit[u];
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        temp.push_back(a[i]);
    }
    sort(all(temp));
    for (int i = 1; i <= n; ++i)
        a[i] = lower_bound(all(temp), a[i]) - temp.begin() + 1;

    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;

    for (int i = 1; i <= n; ++i) update(i, 1);

    int res = 0;

    for (int i = 1; i <= n; ++i) {
        int order = get(a[i]);
        add(res, 1LL * (order - 1) * fac[n - i] % mod);
        update(a[i], -1);
    }

    cout << (res + 1) % mod;

    return 0;
}

/*

[k, 1, 2,.., k - 1, k + 1,.., n]
-> (k - 1) * (n - 1)! ways

-> (order - 1) * (n - i)! ways

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4448 KB Output is correct
12 Correct 1 ms 4448 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4448 KB Output is correct
17 Correct 1 ms 4448 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4852 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 54 ms 15052 KB Output is correct
3 Correct 54 ms 15048 KB Output is correct
4 Correct 58 ms 15048 KB Output is correct
5 Correct 57 ms 14928 KB Output is correct
6 Correct 54 ms 15052 KB Output is correct
7 Correct 53 ms 15072 KB Output is correct
8 Correct 52 ms 14872 KB Output is correct
9 Correct 53 ms 15048 KB Output is correct
10 Correct 57 ms 15108 KB Output is correct
11 Correct 52 ms 14928 KB Output is correct
12 Correct 55 ms 14928 KB Output is correct
13 Correct 56 ms 14928 KB Output is correct
14 Correct 53 ms 15044 KB Output is correct
15 Correct 55 ms 14944 KB Output is correct
16 Correct 52 ms 14948 KB Output is correct
17 Correct 52 ms 15000 KB Output is correct
18 Correct 53 ms 14916 KB Output is correct
19 Correct 53 ms 15048 KB Output is correct
20 Correct 61 ms 15044 KB Output is correct
21 Correct 57 ms 15052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 47 ms 13932 KB Output is correct
3 Correct 47 ms 14036 KB Output is correct
4 Correct 48 ms 14024 KB Output is correct
5 Correct 47 ms 14000 KB Output is correct
6 Correct 52 ms 13976 KB Output is correct
7 Correct 47 ms 13980 KB Output is correct
8 Correct 47 ms 13896 KB Output is correct
9 Correct 48 ms 14036 KB Output is correct
10 Correct 48 ms 14224 KB Output is correct
11 Correct 48 ms 14024 KB Output is correct
12 Correct 50 ms 14028 KB Output is correct
13 Correct 48 ms 13992 KB Output is correct
14 Correct 48 ms 14084 KB Output is correct
15 Correct 57 ms 13908 KB Output is correct
16 Correct 48 ms 13976 KB Output is correct
17 Correct 66 ms 13968 KB Output is correct
18 Correct 47 ms 14020 KB Output is correct
19 Correct 67 ms 13968 KB Output is correct
20 Correct 47 ms 14024 KB Output is correct
21 Correct 54 ms 13984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4620 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4584 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4580 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4580 KB Output is correct
20 Correct 2 ms 4580 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4448 KB Output is correct
12 Correct 1 ms 4448 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4448 KB Output is correct
17 Correct 1 ms 4448 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4852 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4620 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 2 ms 4584 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 1 ms 4580 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 1 ms 4580 KB Output is correct
44 Correct 2 ms 4580 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 2 ms 4516 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4492 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 2 ms 4624 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 2 ms 4444 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 2 ms 4580 KB Output is correct
60 Correct 2 ms 4444 KB Output is correct
61 Correct 1 ms 4448 KB Output is correct
62 Correct 2 ms 4444 KB Output is correct
63 Correct 2 ms 4444 KB Output is correct
64 Correct 2 ms 4444 KB Output is correct
65 Correct 2 ms 4444 KB Output is correct
66 Correct 2 ms 4444 KB Output is correct
67 Correct 2 ms 4444 KB Output is correct
68 Correct 1 ms 4584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 47 ms 13932 KB Output is correct
3 Correct 47 ms 14036 KB Output is correct
4 Correct 48 ms 14024 KB Output is correct
5 Correct 47 ms 14000 KB Output is correct
6 Correct 52 ms 13976 KB Output is correct
7 Correct 47 ms 13980 KB Output is correct
8 Correct 47 ms 13896 KB Output is correct
9 Correct 48 ms 14036 KB Output is correct
10 Correct 48 ms 14224 KB Output is correct
11 Correct 48 ms 14024 KB Output is correct
12 Correct 50 ms 14028 KB Output is correct
13 Correct 48 ms 13992 KB Output is correct
14 Correct 48 ms 14084 KB Output is correct
15 Correct 57 ms 13908 KB Output is correct
16 Correct 48 ms 13976 KB Output is correct
17 Correct 66 ms 13968 KB Output is correct
18 Correct 47 ms 14020 KB Output is correct
19 Correct 67 ms 13968 KB Output is correct
20 Correct 47 ms 14024 KB Output is correct
21 Correct 54 ms 13984 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 2 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4620 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4584 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 1 ms 4580 KB Output is correct
39 Correct 2 ms 4444 KB Output is correct
40 Correct 1 ms 4580 KB Output is correct
41 Correct 2 ms 4580 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4448 KB Output is correct
45 Correct 95 ms 14028 KB Output is correct
46 Correct 104 ms 13968 KB Output is correct
47 Correct 100 ms 14032 KB Output is correct
48 Correct 103 ms 13976 KB Output is correct
49 Correct 100 ms 13980 KB Output is correct
50 Correct 103 ms 13976 KB Output is correct
51 Correct 110 ms 14140 KB Output is correct
52 Correct 96 ms 13980 KB Output is correct
53 Correct 98 ms 14024 KB Output is correct
54 Correct 100 ms 13960 KB Output is correct
55 Correct 118 ms 13964 KB Output is correct
56 Correct 106 ms 14024 KB Output is correct
57 Correct 97 ms 13976 KB Output is correct
58 Correct 1 ms 4564 KB Output is correct
59 Correct 105 ms 13968 KB Output is correct
60 Correct 111 ms 13964 KB Output is correct
61 Correct 95 ms 14028 KB Output is correct
62 Correct 99 ms 13964 KB Output is correct
63 Correct 93 ms 14044 KB Output is correct
64 Correct 94 ms 13956 KB Output is correct
65 Correct 94 ms 14020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4448 KB Output is correct
11 Correct 1 ms 4448 KB Output is correct
12 Correct 1 ms 4448 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4448 KB Output is correct
17 Correct 1 ms 4448 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4852 KB Output is correct
22 Correct 1 ms 4600 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 54 ms 15052 KB Output is correct
27 Correct 54 ms 15048 KB Output is correct
28 Correct 58 ms 15048 KB Output is correct
29 Correct 57 ms 14928 KB Output is correct
30 Correct 54 ms 15052 KB Output is correct
31 Correct 53 ms 15072 KB Output is correct
32 Correct 52 ms 14872 KB Output is correct
33 Correct 53 ms 15048 KB Output is correct
34 Correct 57 ms 15108 KB Output is correct
35 Correct 52 ms 14928 KB Output is correct
36 Correct 55 ms 14928 KB Output is correct
37 Correct 56 ms 14928 KB Output is correct
38 Correct 53 ms 15044 KB Output is correct
39 Correct 55 ms 14944 KB Output is correct
40 Correct 52 ms 14948 KB Output is correct
41 Correct 52 ms 15000 KB Output is correct
42 Correct 53 ms 14916 KB Output is correct
43 Correct 53 ms 15048 KB Output is correct
44 Correct 61 ms 15044 KB Output is correct
45 Correct 57 ms 15052 KB Output is correct
46 Correct 1 ms 4440 KB Output is correct
47 Correct 47 ms 13932 KB Output is correct
48 Correct 47 ms 14036 KB Output is correct
49 Correct 48 ms 14024 KB Output is correct
50 Correct 47 ms 14000 KB Output is correct
51 Correct 52 ms 13976 KB Output is correct
52 Correct 47 ms 13980 KB Output is correct
53 Correct 47 ms 13896 KB Output is correct
54 Correct 48 ms 14036 KB Output is correct
55 Correct 48 ms 14224 KB Output is correct
56 Correct 48 ms 14024 KB Output is correct
57 Correct 50 ms 14028 KB Output is correct
58 Correct 48 ms 13992 KB Output is correct
59 Correct 48 ms 14084 KB Output is correct
60 Correct 57 ms 13908 KB Output is correct
61 Correct 48 ms 13976 KB Output is correct
62 Correct 66 ms 13968 KB Output is correct
63 Correct 47 ms 14020 KB Output is correct
64 Correct 67 ms 13968 KB Output is correct
65 Correct 47 ms 14024 KB Output is correct
66 Correct 54 ms 13984 KB Output is correct
67 Correct 1 ms 4440 KB Output is correct
68 Correct 1 ms 4440 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 2 ms 4440 KB Output is correct
72 Correct 1 ms 4444 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 2 ms 4444 KB Output is correct
75 Correct 2 ms 4444 KB Output is correct
76 Correct 2 ms 4444 KB Output is correct
77 Correct 1 ms 4444 KB Output is correct
78 Correct 1 ms 4620 KB Output is correct
79 Correct 2 ms 4444 KB Output is correct
80 Correct 2 ms 4584 KB Output is correct
81 Correct 1 ms 4444 KB Output is correct
82 Correct 2 ms 4444 KB Output is correct
83 Correct 1 ms 4580 KB Output is correct
84 Correct 2 ms 4444 KB Output is correct
85 Correct 1 ms 4580 KB Output is correct
86 Correct 2 ms 4580 KB Output is correct
87 Correct 2 ms 4444 KB Output is correct
88 Correct 1 ms 4444 KB Output is correct
89 Correct 1 ms 4444 KB Output is correct
90 Correct 1 ms 4444 KB Output is correct
91 Correct 1 ms 4444 KB Output is correct
92 Correct 2 ms 4516 KB Output is correct
93 Correct 2 ms 4444 KB Output is correct
94 Correct 2 ms 4492 KB Output is correct
95 Correct 2 ms 4444 KB Output is correct
96 Correct 2 ms 4624 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4444 KB Output is correct
99 Correct 2 ms 4444 KB Output is correct
100 Correct 2 ms 4444 KB Output is correct
101 Correct 2 ms 4580 KB Output is correct
102 Correct 2 ms 4444 KB Output is correct
103 Correct 1 ms 4448 KB Output is correct
104 Correct 2 ms 4444 KB Output is correct
105 Correct 2 ms 4444 KB Output is correct
106 Correct 2 ms 4444 KB Output is correct
107 Correct 2 ms 4444 KB Output is correct
108 Correct 2 ms 4444 KB Output is correct
109 Correct 2 ms 4444 KB Output is correct
110 Correct 1 ms 4584 KB Output is correct
111 Correct 1 ms 4448 KB Output is correct
112 Correct 95 ms 14028 KB Output is correct
113 Correct 104 ms 13968 KB Output is correct
114 Correct 100 ms 14032 KB Output is correct
115 Correct 103 ms 13976 KB Output is correct
116 Correct 100 ms 13980 KB Output is correct
117 Correct 103 ms 13976 KB Output is correct
118 Correct 110 ms 14140 KB Output is correct
119 Correct 96 ms 13980 KB Output is correct
120 Correct 98 ms 14024 KB Output is correct
121 Correct 100 ms 13960 KB Output is correct
122 Correct 118 ms 13964 KB Output is correct
123 Correct 106 ms 14024 KB Output is correct
124 Correct 97 ms 13976 KB Output is correct
125 Correct 1 ms 4564 KB Output is correct
126 Correct 105 ms 13968 KB Output is correct
127 Correct 111 ms 13964 KB Output is correct
128 Correct 95 ms 14028 KB Output is correct
129 Correct 99 ms 13964 KB Output is correct
130 Correct 93 ms 14044 KB Output is correct
131 Correct 94 ms 13956 KB Output is correct
132 Correct 94 ms 14020 KB Output is correct
133 Correct 1 ms 4444 KB Output is correct
134 Correct 102 ms 15044 KB Output is correct
135 Correct 97 ms 14920 KB Output is correct
136 Correct 109 ms 15044 KB Output is correct
137 Correct 96 ms 15048 KB Output is correct
138 Correct 99 ms 14928 KB Output is correct
139 Correct 99 ms 15044 KB Output is correct
140 Correct 101 ms 14924 KB Output is correct
141 Correct 97 ms 14920 KB Output is correct
142 Correct 97 ms 15048 KB Output is correct
143 Correct 97 ms 14920 KB Output is correct
144 Correct 97 ms 15048 KB Output is correct
145 Correct 97 ms 15044 KB Output is correct
146 Correct 101 ms 14972 KB Output is correct
147 Correct 1 ms 4444 KB Output is correct
148 Correct 96 ms 14940 KB Output is correct
149 Correct 97 ms 15036 KB Output is correct
150 Correct 98 ms 14928 KB Output is correct
151 Correct 97 ms 15044 KB Output is correct
152 Correct 98 ms 15048 KB Output is correct
153 Correct 100 ms 14920 KB Output is correct
154 Correct 100 ms 15184 KB Output is correct