답안 #337524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337524 2020-12-21T04:03:36 Z ncduy0303 Cryptography (NOI20_crypto) C++17
100 / 100
378 ms 23404 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 3e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

vector<ll> fact;

void precompute(int n) {
    fact.assign(n + 1, 1); 
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
}

void solve() {
    int n; cin >> n;
    vector<ar<int,2>> a(n);
    for (int i = 0; i < n; i++) cin >> a[i][0], a[i][1] = i;
    sort(a.begin(), a.end());
    vector<int> b(n);
    for (int i = 0; i < n; i++) b[a[i][1]] = i;
    int ans = 1;
    ordered_set<int> os;
    for (int i = 0; i < n; i++) {
        int cnt = os.order_of_key(b[i]);
        ans = (ans + fact[n - i - 1] * (b[i] - cnt) % MOD) % MOD;
        os.insert(b[i]);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    precompute(MAX_N);
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 4 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
7 Correct 4 ms 2668 KB Output is correct
8 Correct 4 ms 2668 KB Output is correct
9 Correct 4 ms 2668 KB Output is correct
10 Correct 4 ms 2668 KB Output is correct
11 Correct 4 ms 2668 KB Output is correct
12 Correct 4 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Correct 4 ms 2668 KB Output is correct
16 Correct 4 ms 2668 KB Output is correct
17 Correct 4 ms 2668 KB Output is correct
18 Correct 4 ms 2668 KB Output is correct
19 Correct 4 ms 2668 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 5 ms 2796 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 309 ms 23404 KB Output is correct
3 Correct 296 ms 23148 KB Output is correct
4 Correct 296 ms 23276 KB Output is correct
5 Correct 314 ms 23148 KB Output is correct
6 Correct 299 ms 23404 KB Output is correct
7 Correct 319 ms 23276 KB Output is correct
8 Correct 330 ms 23212 KB Output is correct
9 Correct 324 ms 23276 KB Output is correct
10 Correct 318 ms 23276 KB Output is correct
11 Correct 322 ms 23168 KB Output is correct
12 Correct 310 ms 23148 KB Output is correct
13 Correct 305 ms 23276 KB Output is correct
14 Correct 304 ms 23220 KB Output is correct
15 Correct 322 ms 23160 KB Output is correct
16 Correct 327 ms 23148 KB Output is correct
17 Correct 349 ms 23344 KB Output is correct
18 Correct 333 ms 23276 KB Output is correct
19 Correct 307 ms 23140 KB Output is correct
20 Correct 309 ms 23268 KB Output is correct
21 Correct 298 ms 23276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 306 ms 22252 KB Output is correct
3 Correct 317 ms 22508 KB Output is correct
4 Correct 305 ms 22252 KB Output is correct
5 Correct 293 ms 22264 KB Output is correct
6 Correct 295 ms 22252 KB Output is correct
7 Correct 311 ms 22252 KB Output is correct
8 Correct 309 ms 22280 KB Output is correct
9 Correct 309 ms 22252 KB Output is correct
10 Correct 298 ms 22380 KB Output is correct
11 Correct 300 ms 22252 KB Output is correct
12 Correct 307 ms 22252 KB Output is correct
13 Correct 303 ms 22252 KB Output is correct
14 Correct 316 ms 22252 KB Output is correct
15 Correct 306 ms 22252 KB Output is correct
16 Correct 294 ms 22380 KB Output is correct
17 Correct 292 ms 22428 KB Output is correct
18 Correct 295 ms 22252 KB Output is correct
19 Correct 300 ms 22380 KB Output is correct
20 Correct 301 ms 22252 KB Output is correct
21 Correct 297 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 6 ms 2924 KB Output is correct
3 Correct 5 ms 2924 KB Output is correct
4 Correct 6 ms 2924 KB Output is correct
5 Correct 6 ms 2924 KB Output is correct
6 Correct 6 ms 2924 KB Output is correct
7 Correct 6 ms 2924 KB Output is correct
8 Correct 6 ms 2924 KB Output is correct
9 Correct 6 ms 2924 KB Output is correct
10 Correct 6 ms 2924 KB Output is correct
11 Correct 6 ms 2924 KB Output is correct
12 Correct 6 ms 2924 KB Output is correct
13 Correct 6 ms 2924 KB Output is correct
14 Correct 6 ms 2924 KB Output is correct
15 Correct 4 ms 2668 KB Output is correct
16 Correct 6 ms 2924 KB Output is correct
17 Correct 6 ms 2924 KB Output is correct
18 Correct 6 ms 2924 KB Output is correct
19 Correct 5 ms 2924 KB Output is correct
20 Correct 6 ms 2924 KB Output is correct
21 Correct 6 ms 2924 KB Output is correct
22 Correct 6 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 4 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
7 Correct 4 ms 2668 KB Output is correct
8 Correct 4 ms 2668 KB Output is correct
9 Correct 4 ms 2668 KB Output is correct
10 Correct 4 ms 2668 KB Output is correct
11 Correct 4 ms 2668 KB Output is correct
12 Correct 4 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Correct 4 ms 2668 KB Output is correct
16 Correct 4 ms 2668 KB Output is correct
17 Correct 4 ms 2668 KB Output is correct
18 Correct 4 ms 2668 KB Output is correct
19 Correct 4 ms 2668 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 5 ms 2796 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2668 KB Output is correct
25 Correct 4 ms 2668 KB Output is correct
26 Correct 6 ms 2924 KB Output is correct
27 Correct 5 ms 2924 KB Output is correct
28 Correct 6 ms 2924 KB Output is correct
29 Correct 6 ms 2924 KB Output is correct
30 Correct 6 ms 2924 KB Output is correct
31 Correct 6 ms 2924 KB Output is correct
32 Correct 6 ms 2924 KB Output is correct
33 Correct 6 ms 2924 KB Output is correct
34 Correct 6 ms 2924 KB Output is correct
35 Correct 6 ms 2924 KB Output is correct
36 Correct 6 ms 2924 KB Output is correct
37 Correct 6 ms 2924 KB Output is correct
38 Correct 6 ms 2924 KB Output is correct
39 Correct 4 ms 2668 KB Output is correct
40 Correct 6 ms 2924 KB Output is correct
41 Correct 6 ms 2924 KB Output is correct
42 Correct 6 ms 2924 KB Output is correct
43 Correct 5 ms 2924 KB Output is correct
44 Correct 6 ms 2924 KB Output is correct
45 Correct 6 ms 2924 KB Output is correct
46 Correct 6 ms 2924 KB Output is correct
47 Correct 4 ms 2668 KB Output is correct
48 Correct 6 ms 2924 KB Output is correct
49 Correct 6 ms 2924 KB Output is correct
50 Correct 6 ms 2924 KB Output is correct
51 Correct 6 ms 2924 KB Output is correct
52 Correct 6 ms 2924 KB Output is correct
53 Correct 6 ms 2924 KB Output is correct
54 Correct 6 ms 2924 KB Output is correct
55 Correct 6 ms 2924 KB Output is correct
56 Correct 6 ms 2924 KB Output is correct
57 Correct 6 ms 2944 KB Output is correct
58 Correct 6 ms 2924 KB Output is correct
59 Correct 6 ms 2924 KB Output is correct
60 Correct 6 ms 2924 KB Output is correct
61 Correct 4 ms 2668 KB Output is correct
62 Correct 6 ms 2924 KB Output is correct
63 Correct 7 ms 2924 KB Output is correct
64 Correct 6 ms 2924 KB Output is correct
65 Correct 7 ms 2924 KB Output is correct
66 Correct 6 ms 2924 KB Output is correct
67 Correct 6 ms 2924 KB Output is correct
68 Correct 6 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 306 ms 22252 KB Output is correct
3 Correct 317 ms 22508 KB Output is correct
4 Correct 305 ms 22252 KB Output is correct
5 Correct 293 ms 22264 KB Output is correct
6 Correct 295 ms 22252 KB Output is correct
7 Correct 311 ms 22252 KB Output is correct
8 Correct 309 ms 22280 KB Output is correct
9 Correct 309 ms 22252 KB Output is correct
10 Correct 298 ms 22380 KB Output is correct
11 Correct 300 ms 22252 KB Output is correct
12 Correct 307 ms 22252 KB Output is correct
13 Correct 303 ms 22252 KB Output is correct
14 Correct 316 ms 22252 KB Output is correct
15 Correct 306 ms 22252 KB Output is correct
16 Correct 294 ms 22380 KB Output is correct
17 Correct 292 ms 22428 KB Output is correct
18 Correct 295 ms 22252 KB Output is correct
19 Correct 300 ms 22380 KB Output is correct
20 Correct 301 ms 22252 KB Output is correct
21 Correct 297 ms 22252 KB Output is correct
22 Correct 4 ms 2668 KB Output is correct
23 Correct 6 ms 2924 KB Output is correct
24 Correct 5 ms 2924 KB Output is correct
25 Correct 6 ms 2924 KB Output is correct
26 Correct 6 ms 2924 KB Output is correct
27 Correct 6 ms 2924 KB Output is correct
28 Correct 6 ms 2924 KB Output is correct
29 Correct 6 ms 2924 KB Output is correct
30 Correct 6 ms 2924 KB Output is correct
31 Correct 6 ms 2924 KB Output is correct
32 Correct 6 ms 2924 KB Output is correct
33 Correct 6 ms 2924 KB Output is correct
34 Correct 6 ms 2924 KB Output is correct
35 Correct 6 ms 2924 KB Output is correct
36 Correct 4 ms 2668 KB Output is correct
37 Correct 6 ms 2924 KB Output is correct
38 Correct 6 ms 2924 KB Output is correct
39 Correct 6 ms 2924 KB Output is correct
40 Correct 5 ms 2924 KB Output is correct
41 Correct 6 ms 2924 KB Output is correct
42 Correct 6 ms 2924 KB Output is correct
43 Correct 6 ms 2924 KB Output is correct
44 Correct 4 ms 2668 KB Output is correct
45 Correct 356 ms 22380 KB Output is correct
46 Correct 349 ms 22252 KB Output is correct
47 Correct 351 ms 22224 KB Output is correct
48 Correct 359 ms 22404 KB Output is correct
49 Correct 352 ms 22296 KB Output is correct
50 Correct 360 ms 22380 KB Output is correct
51 Correct 355 ms 22252 KB Output is correct
52 Correct 378 ms 22252 KB Output is correct
53 Correct 330 ms 22252 KB Output is correct
54 Correct 325 ms 22252 KB Output is correct
55 Correct 331 ms 22380 KB Output is correct
56 Correct 322 ms 22252 KB Output is correct
57 Correct 337 ms 22380 KB Output is correct
58 Correct 4 ms 2668 KB Output is correct
59 Correct 319 ms 22252 KB Output is correct
60 Correct 341 ms 22408 KB Output is correct
61 Correct 321 ms 22252 KB Output is correct
62 Correct 331 ms 22380 KB Output is correct
63 Correct 333 ms 22252 KB Output is correct
64 Correct 337 ms 22380 KB Output is correct
65 Correct 336 ms 22180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 4 ms 2668 KB Output is correct
4 Correct 4 ms 2668 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2668 KB Output is correct
7 Correct 4 ms 2668 KB Output is correct
8 Correct 4 ms 2668 KB Output is correct
9 Correct 4 ms 2668 KB Output is correct
10 Correct 4 ms 2668 KB Output is correct
11 Correct 4 ms 2668 KB Output is correct
12 Correct 4 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Correct 4 ms 2668 KB Output is correct
16 Correct 4 ms 2668 KB Output is correct
17 Correct 4 ms 2668 KB Output is correct
18 Correct 4 ms 2668 KB Output is correct
19 Correct 4 ms 2668 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 5 ms 2796 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2668 KB Output is correct
25 Correct 4 ms 2668 KB Output is correct
26 Correct 309 ms 23404 KB Output is correct
27 Correct 296 ms 23148 KB Output is correct
28 Correct 296 ms 23276 KB Output is correct
29 Correct 314 ms 23148 KB Output is correct
30 Correct 299 ms 23404 KB Output is correct
31 Correct 319 ms 23276 KB Output is correct
32 Correct 330 ms 23212 KB Output is correct
33 Correct 324 ms 23276 KB Output is correct
34 Correct 318 ms 23276 KB Output is correct
35 Correct 322 ms 23168 KB Output is correct
36 Correct 310 ms 23148 KB Output is correct
37 Correct 305 ms 23276 KB Output is correct
38 Correct 304 ms 23220 KB Output is correct
39 Correct 322 ms 23160 KB Output is correct
40 Correct 327 ms 23148 KB Output is correct
41 Correct 349 ms 23344 KB Output is correct
42 Correct 333 ms 23276 KB Output is correct
43 Correct 307 ms 23140 KB Output is correct
44 Correct 309 ms 23268 KB Output is correct
45 Correct 298 ms 23276 KB Output is correct
46 Correct 4 ms 2668 KB Output is correct
47 Correct 306 ms 22252 KB Output is correct
48 Correct 317 ms 22508 KB Output is correct
49 Correct 305 ms 22252 KB Output is correct
50 Correct 293 ms 22264 KB Output is correct
51 Correct 295 ms 22252 KB Output is correct
52 Correct 311 ms 22252 KB Output is correct
53 Correct 309 ms 22280 KB Output is correct
54 Correct 309 ms 22252 KB Output is correct
55 Correct 298 ms 22380 KB Output is correct
56 Correct 300 ms 22252 KB Output is correct
57 Correct 307 ms 22252 KB Output is correct
58 Correct 303 ms 22252 KB Output is correct
59 Correct 316 ms 22252 KB Output is correct
60 Correct 306 ms 22252 KB Output is correct
61 Correct 294 ms 22380 KB Output is correct
62 Correct 292 ms 22428 KB Output is correct
63 Correct 295 ms 22252 KB Output is correct
64 Correct 300 ms 22380 KB Output is correct
65 Correct 301 ms 22252 KB Output is correct
66 Correct 297 ms 22252 KB Output is correct
67 Correct 4 ms 2668 KB Output is correct
68 Correct 6 ms 2924 KB Output is correct
69 Correct 5 ms 2924 KB Output is correct
70 Correct 6 ms 2924 KB Output is correct
71 Correct 6 ms 2924 KB Output is correct
72 Correct 6 ms 2924 KB Output is correct
73 Correct 6 ms 2924 KB Output is correct
74 Correct 6 ms 2924 KB Output is correct
75 Correct 6 ms 2924 KB Output is correct
76 Correct 6 ms 2924 KB Output is correct
77 Correct 6 ms 2924 KB Output is correct
78 Correct 6 ms 2924 KB Output is correct
79 Correct 6 ms 2924 KB Output is correct
80 Correct 6 ms 2924 KB Output is correct
81 Correct 4 ms 2668 KB Output is correct
82 Correct 6 ms 2924 KB Output is correct
83 Correct 6 ms 2924 KB Output is correct
84 Correct 6 ms 2924 KB Output is correct
85 Correct 5 ms 2924 KB Output is correct
86 Correct 6 ms 2924 KB Output is correct
87 Correct 6 ms 2924 KB Output is correct
88 Correct 6 ms 2924 KB Output is correct
89 Correct 4 ms 2668 KB Output is correct
90 Correct 6 ms 2924 KB Output is correct
91 Correct 6 ms 2924 KB Output is correct
92 Correct 6 ms 2924 KB Output is correct
93 Correct 6 ms 2924 KB Output is correct
94 Correct 6 ms 2924 KB Output is correct
95 Correct 6 ms 2924 KB Output is correct
96 Correct 6 ms 2924 KB Output is correct
97 Correct 6 ms 2924 KB Output is correct
98 Correct 6 ms 2924 KB Output is correct
99 Correct 6 ms 2944 KB Output is correct
100 Correct 6 ms 2924 KB Output is correct
101 Correct 6 ms 2924 KB Output is correct
102 Correct 6 ms 2924 KB Output is correct
103 Correct 4 ms 2668 KB Output is correct
104 Correct 6 ms 2924 KB Output is correct
105 Correct 7 ms 2924 KB Output is correct
106 Correct 6 ms 2924 KB Output is correct
107 Correct 7 ms 2924 KB Output is correct
108 Correct 6 ms 2924 KB Output is correct
109 Correct 6 ms 2924 KB Output is correct
110 Correct 6 ms 2924 KB Output is correct
111 Correct 4 ms 2668 KB Output is correct
112 Correct 356 ms 22380 KB Output is correct
113 Correct 349 ms 22252 KB Output is correct
114 Correct 351 ms 22224 KB Output is correct
115 Correct 359 ms 22404 KB Output is correct
116 Correct 352 ms 22296 KB Output is correct
117 Correct 360 ms 22380 KB Output is correct
118 Correct 355 ms 22252 KB Output is correct
119 Correct 378 ms 22252 KB Output is correct
120 Correct 330 ms 22252 KB Output is correct
121 Correct 325 ms 22252 KB Output is correct
122 Correct 331 ms 22380 KB Output is correct
123 Correct 322 ms 22252 KB Output is correct
124 Correct 337 ms 22380 KB Output is correct
125 Correct 4 ms 2668 KB Output is correct
126 Correct 319 ms 22252 KB Output is correct
127 Correct 341 ms 22408 KB Output is correct
128 Correct 321 ms 22252 KB Output is correct
129 Correct 331 ms 22380 KB Output is correct
130 Correct 333 ms 22252 KB Output is correct
131 Correct 337 ms 22380 KB Output is correct
132 Correct 336 ms 22180 KB Output is correct
133 Correct 4 ms 2668 KB Output is correct
134 Correct 336 ms 23232 KB Output is correct
135 Correct 332 ms 23148 KB Output is correct
136 Correct 342 ms 23148 KB Output is correct
137 Correct 333 ms 23276 KB Output is correct
138 Correct 338 ms 23148 KB Output is correct
139 Correct 339 ms 23148 KB Output is correct
140 Correct 341 ms 23276 KB Output is correct
141 Correct 336 ms 23348 KB Output is correct
142 Correct 339 ms 23276 KB Output is correct
143 Correct 334 ms 23276 KB Output is correct
144 Correct 346 ms 23276 KB Output is correct
145 Correct 331 ms 23148 KB Output is correct
146 Correct 336 ms 23148 KB Output is correct
147 Correct 4 ms 2668 KB Output is correct
148 Correct 333 ms 23148 KB Output is correct
149 Correct 337 ms 23148 KB Output is correct
150 Correct 349 ms 23276 KB Output is correct
151 Correct 367 ms 23404 KB Output is correct
152 Correct 346 ms 23148 KB Output is correct
153 Correct 335 ms 23276 KB Output is correct
154 Correct 331 ms 23148 KB Output is correct