답안 #861701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861701 2023-10-16T16:49:12 Z wakandaaa Cryptography (NOI20_crypto) C++17
100 / 100
110 ms 15816 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;
}

/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4700 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 4572 KB Output is correct
7 Correct 1 ms 4440 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 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 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 4444 KB Output is correct
17 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
22 Correct 1 ms 4536 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 54 ms 14880 KB Output is correct
3 Correct 54 ms 15016 KB Output is correct
4 Correct 54 ms 15060 KB Output is correct
5 Correct 55 ms 14936 KB Output is correct
6 Correct 53 ms 15048 KB Output is correct
7 Correct 56 ms 14916 KB Output is correct
8 Correct 52 ms 14972 KB Output is correct
9 Correct 52 ms 14920 KB Output is correct
10 Correct 51 ms 15040 KB Output is correct
11 Correct 52 ms 14928 KB Output is correct
12 Correct 53 ms 15052 KB Output is correct
13 Correct 54 ms 14992 KB Output is correct
14 Correct 53 ms 15816 KB Output is correct
15 Correct 52 ms 14928 KB Output is correct
16 Correct 51 ms 15044 KB Output is correct
17 Correct 53 ms 15264 KB Output is correct
18 Correct 52 ms 15024 KB Output is correct
19 Correct 55 ms 14936 KB Output is correct
20 Correct 53 ms 14924 KB Output is correct
21 Correct 53 ms 15052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 47 ms 13980 KB Output is correct
3 Correct 54 ms 13968 KB Output is correct
4 Correct 47 ms 14020 KB Output is correct
5 Correct 47 ms 14024 KB Output is correct
6 Correct 47 ms 14024 KB Output is correct
7 Correct 47 ms 13980 KB Output is correct
8 Correct 48 ms 13940 KB Output is correct
9 Correct 47 ms 14028 KB Output is correct
10 Correct 47 ms 14048 KB Output is correct
11 Correct 46 ms 13964 KB Output is correct
12 Correct 51 ms 14036 KB Output is correct
13 Correct 52 ms 13960 KB Output is correct
14 Correct 46 ms 13952 KB Output is correct
15 Correct 47 ms 14092 KB Output is correct
16 Correct 47 ms 13956 KB Output is correct
17 Correct 57 ms 14020 KB Output is correct
18 Correct 47 ms 14036 KB Output is correct
19 Correct 47 ms 14024 KB Output is correct
20 Correct 46 ms 14024 KB Output is correct
21 Correct 46 ms 13976 KB Output is correct
# 결과 실행 시간 메모리 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4440 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 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 1 ms 4440 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 4 ms 4444 KB Output is correct
17 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4700 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 4572 KB Output is correct
7 Correct 1 ms 4440 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 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 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 4444 KB Output is correct
17 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
22 Correct 1 ms 4536 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 4 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 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 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4616 KB Output is correct
53 Correct 1 ms 4440 KB Output is correct
54 Correct 1 ms 4440 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4636 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 2 ms 4444 KB Output is correct
59 Correct 1 ms 4440 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 2 ms 4440 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 1 ms 4444 KB Output is correct
66 Correct 1 ms 4440 KB Output is correct
67 Correct 1 ms 4440 KB Output is correct
68 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 47 ms 13980 KB Output is correct
3 Correct 54 ms 13968 KB Output is correct
4 Correct 47 ms 14020 KB Output is correct
5 Correct 47 ms 14024 KB Output is correct
6 Correct 47 ms 14024 KB Output is correct
7 Correct 47 ms 13980 KB Output is correct
8 Correct 48 ms 13940 KB Output is correct
9 Correct 47 ms 14028 KB Output is correct
10 Correct 47 ms 14048 KB Output is correct
11 Correct 46 ms 13964 KB Output is correct
12 Correct 51 ms 14036 KB Output is correct
13 Correct 52 ms 13960 KB Output is correct
14 Correct 46 ms 13952 KB Output is correct
15 Correct 47 ms 14092 KB Output is correct
16 Correct 47 ms 13956 KB Output is correct
17 Correct 57 ms 14020 KB Output is correct
18 Correct 47 ms 14036 KB Output is correct
19 Correct 47 ms 14024 KB Output is correct
20 Correct 46 ms 14024 KB Output is correct
21 Correct 46 ms 13976 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 2 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 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 1 ms 4440 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 4 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 100 ms 14144 KB Output is correct
46 Correct 96 ms 14020 KB Output is correct
47 Correct 95 ms 13960 KB Output is correct
48 Correct 95 ms 13900 KB Output is correct
49 Correct 100 ms 13964 KB Output is correct
50 Correct 94 ms 13964 KB Output is correct
51 Correct 102 ms 13964 KB Output is correct
52 Correct 97 ms 13960 KB Output is correct
53 Correct 100 ms 14024 KB Output is correct
54 Correct 97 ms 14024 KB Output is correct
55 Correct 94 ms 13984 KB Output is correct
56 Correct 95 ms 14020 KB Output is correct
57 Correct 95 ms 13976 KB Output is correct
58 Correct 1 ms 4440 KB Output is correct
59 Correct 97 ms 13900 KB Output is correct
60 Correct 95 ms 14020 KB Output is correct
61 Correct 95 ms 13960 KB Output is correct
62 Correct 96 ms 14024 KB Output is correct
63 Correct 94 ms 14020 KB Output is correct
64 Correct 93 ms 14016 KB Output is correct
65 Correct 94 ms 13968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4700 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 4572 KB Output is correct
7 Correct 1 ms 4440 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 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 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 4444 KB Output is correct
17 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
22 Correct 1 ms 4536 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 54 ms 14880 KB Output is correct
27 Correct 54 ms 15016 KB Output is correct
28 Correct 54 ms 15060 KB Output is correct
29 Correct 55 ms 14936 KB Output is correct
30 Correct 53 ms 15048 KB Output is correct
31 Correct 56 ms 14916 KB Output is correct
32 Correct 52 ms 14972 KB Output is correct
33 Correct 52 ms 14920 KB Output is correct
34 Correct 51 ms 15040 KB Output is correct
35 Correct 52 ms 14928 KB Output is correct
36 Correct 53 ms 15052 KB Output is correct
37 Correct 54 ms 14992 KB Output is correct
38 Correct 53 ms 15816 KB Output is correct
39 Correct 52 ms 14928 KB Output is correct
40 Correct 51 ms 15044 KB Output is correct
41 Correct 53 ms 15264 KB Output is correct
42 Correct 52 ms 15024 KB Output is correct
43 Correct 55 ms 14936 KB Output is correct
44 Correct 53 ms 14924 KB Output is correct
45 Correct 53 ms 15052 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 47 ms 13980 KB Output is correct
48 Correct 54 ms 13968 KB Output is correct
49 Correct 47 ms 14020 KB Output is correct
50 Correct 47 ms 14024 KB Output is correct
51 Correct 47 ms 14024 KB Output is correct
52 Correct 47 ms 13980 KB Output is correct
53 Correct 48 ms 13940 KB Output is correct
54 Correct 47 ms 14028 KB Output is correct
55 Correct 47 ms 14048 KB Output is correct
56 Correct 46 ms 13964 KB Output is correct
57 Correct 51 ms 14036 KB Output is correct
58 Correct 52 ms 13960 KB Output is correct
59 Correct 46 ms 13952 KB Output is correct
60 Correct 47 ms 14092 KB Output is correct
61 Correct 47 ms 13956 KB Output is correct
62 Correct 57 ms 14020 KB Output is correct
63 Correct 47 ms 14036 KB Output is correct
64 Correct 47 ms 14024 KB Output is correct
65 Correct 46 ms 14024 KB Output is correct
66 Correct 46 ms 13976 KB Output is correct
67 Correct 1 ms 4444 KB Output is correct
68 Correct 1 ms 4444 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 1 ms 4444 KB Output is correct
72 Correct 2 ms 4440 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 1 ms 4444 KB Output is correct
75 Correct 1 ms 4444 KB Output is correct
76 Correct 1 ms 4444 KB Output is correct
77 Correct 2 ms 4444 KB Output is correct
78 Correct 1 ms 4440 KB Output is correct
79 Correct 1 ms 4444 KB Output is correct
80 Correct 1 ms 4444 KB Output is correct
81 Correct 1 ms 4444 KB Output is correct
82 Correct 4 ms 4444 KB Output is correct
83 Correct 1 ms 4444 KB Output is correct
84 Correct 1 ms 4444 KB Output is correct
85 Correct 1 ms 4444 KB Output is correct
86 Correct 1 ms 4444 KB Output is correct
87 Correct 1 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 1 ms 4444 KB Output is correct
93 Correct 1 ms 4444 KB Output is correct
94 Correct 1 ms 4616 KB Output is correct
95 Correct 1 ms 4440 KB Output is correct
96 Correct 1 ms 4440 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4636 KB Output is correct
99 Correct 1 ms 4444 KB Output is correct
100 Correct 2 ms 4444 KB Output is correct
101 Correct 1 ms 4440 KB Output is correct
102 Correct 1 ms 4444 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 1 ms 4444 KB Output is correct
105 Correct 2 ms 4440 KB Output is correct
106 Correct 1 ms 4444 KB Output is correct
107 Correct 1 ms 4444 KB Output is correct
108 Correct 1 ms 4440 KB Output is correct
109 Correct 1 ms 4440 KB Output is correct
110 Correct 1 ms 4444 KB Output is correct
111 Correct 1 ms 4444 KB Output is correct
112 Correct 100 ms 14144 KB Output is correct
113 Correct 96 ms 14020 KB Output is correct
114 Correct 95 ms 13960 KB Output is correct
115 Correct 95 ms 13900 KB Output is correct
116 Correct 100 ms 13964 KB Output is correct
117 Correct 94 ms 13964 KB Output is correct
118 Correct 102 ms 13964 KB Output is correct
119 Correct 97 ms 13960 KB Output is correct
120 Correct 100 ms 14024 KB Output is correct
121 Correct 97 ms 14024 KB Output is correct
122 Correct 94 ms 13984 KB Output is correct
123 Correct 95 ms 14020 KB Output is correct
124 Correct 95 ms 13976 KB Output is correct
125 Correct 1 ms 4440 KB Output is correct
126 Correct 97 ms 13900 KB Output is correct
127 Correct 95 ms 14020 KB Output is correct
128 Correct 95 ms 13960 KB Output is correct
129 Correct 96 ms 14024 KB Output is correct
130 Correct 94 ms 14020 KB Output is correct
131 Correct 93 ms 14016 KB Output is correct
132 Correct 94 ms 13968 KB Output is correct
133 Correct 1 ms 4444 KB Output is correct
134 Correct 102 ms 14924 KB Output is correct
135 Correct 98 ms 15068 KB Output is correct
136 Correct 99 ms 15048 KB Output is correct
137 Correct 98 ms 14936 KB Output is correct
138 Correct 99 ms 15044 KB Output is correct
139 Correct 99 ms 15048 KB Output is correct
140 Correct 103 ms 15048 KB Output is correct
141 Correct 100 ms 15052 KB Output is correct
142 Correct 97 ms 15048 KB Output is correct
143 Correct 100 ms 15044 KB Output is correct
144 Correct 107 ms 14928 KB Output is correct
145 Correct 98 ms 14924 KB Output is correct
146 Correct 102 ms 15048 KB Output is correct
147 Correct 1 ms 4440 KB Output is correct
148 Correct 107 ms 15096 KB Output is correct
149 Correct 110 ms 14928 KB Output is correct
150 Correct 97 ms 15044 KB Output is correct
151 Correct 103 ms 15048 KB Output is correct
152 Correct 100 ms 15044 KB Output is correct
153 Correct 101 ms 14928 KB Output is correct
154 Correct 98 ms 15048 KB Output is correct