답안 #368053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
368053 2021-02-19T11:54:48 Z ncduy0303 Cryptography (NOI20_crypto) C++17
35 / 100
341 ms 20812 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

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

#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<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n; cin >> n;
    vector<ll> fact(n);
    fact[0] = 1;
    for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
    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;
    // for (int x : b) cerr << x << " ";
    // cerr << "\n";
    ll ans = 0;
    ordered_set<int> os;
    for (int i = 0; i < n; i++) {
        os.insert(b[i]);
        ll tmp = fact[n - i - 1] * (b[i] - os.order_of_key(b[i])) % MOD;
        // cerr << tmp << " ";
        ans = (ans + tmp) % MOD; 
    }
    // cerr << "\n";
    cout << ans + 1 << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 303 ms 20520 KB Output is correct
3 Correct 309 ms 20672 KB Output is correct
4 Correct 305 ms 20812 KB Output is correct
5 Correct 295 ms 20612 KB Output is correct
6 Correct 293 ms 20588 KB Output is correct
7 Correct 341 ms 20744 KB Output is correct
8 Correct 312 ms 20588 KB Output is correct
9 Correct 312 ms 20588 KB Output is correct
10 Correct 318 ms 20736 KB Output is correct
11 Correct 318 ms 20600 KB Output is correct
12 Correct 291 ms 20716 KB Output is correct
13 Correct 298 ms 20572 KB Output is correct
14 Correct 296 ms 20588 KB Output is correct
15 Correct 327 ms 20588 KB Output is correct
16 Correct 312 ms 20588 KB Output is correct
17 Correct 319 ms 20800 KB Output is correct
18 Correct 317 ms 20588 KB Output is correct
19 Correct 307 ms 20716 KB Output is correct
20 Correct 297 ms 20560 KB Output is correct
21 Correct 294 ms 20588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 305 ms 20588 KB Output is correct
3 Correct 330 ms 20588 KB Output is correct
4 Correct 296 ms 20588 KB Output is correct
5 Correct 298 ms 20736 KB Output is correct
6 Correct 296 ms 20588 KB Output is correct
7 Correct 307 ms 20628 KB Output is correct
8 Correct 311 ms 20716 KB Output is correct
9 Correct 318 ms 20588 KB Output is correct
10 Correct 296 ms 20588 KB Output is correct
11 Correct 294 ms 20716 KB Output is correct
12 Correct 304 ms 20716 KB Output is correct
13 Correct 292 ms 20576 KB Output is correct
14 Correct 293 ms 20704 KB Output is correct
15 Correct 312 ms 20560 KB Output is correct
16 Correct 290 ms 20588 KB Output is correct
17 Correct 315 ms 20552 KB Output is correct
18 Correct 311 ms 20588 KB Output is correct
19 Correct 295 ms 20768 KB Output is correct
20 Correct 297 ms 20548 KB Output is correct
21 Correct 286 ms 20716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 3 ms 492 KB Output is correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 305 ms 20588 KB Output is correct
3 Correct 330 ms 20588 KB Output is correct
4 Correct 296 ms 20588 KB Output is correct
5 Correct 298 ms 20736 KB Output is correct
6 Correct 296 ms 20588 KB Output is correct
7 Correct 307 ms 20628 KB Output is correct
8 Correct 311 ms 20716 KB Output is correct
9 Correct 318 ms 20588 KB Output is correct
10 Correct 296 ms 20588 KB Output is correct
11 Correct 294 ms 20716 KB Output is correct
12 Correct 304 ms 20716 KB Output is correct
13 Correct 292 ms 20576 KB Output is correct
14 Correct 293 ms 20704 KB Output is correct
15 Correct 312 ms 20560 KB Output is correct
16 Correct 290 ms 20588 KB Output is correct
17 Correct 315 ms 20552 KB Output is correct
18 Correct 311 ms 20588 KB Output is correct
19 Correct 295 ms 20768 KB Output is correct
20 Correct 297 ms 20548 KB Output is correct
21 Correct 286 ms 20716 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Incorrect 1 ms 364 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 303 ms 20520 KB Output is correct
27 Correct 309 ms 20672 KB Output is correct
28 Correct 305 ms 20812 KB Output is correct
29 Correct 295 ms 20612 KB Output is correct
30 Correct 293 ms 20588 KB Output is correct
31 Correct 341 ms 20744 KB Output is correct
32 Correct 312 ms 20588 KB Output is correct
33 Correct 312 ms 20588 KB Output is correct
34 Correct 318 ms 20736 KB Output is correct
35 Correct 318 ms 20600 KB Output is correct
36 Correct 291 ms 20716 KB Output is correct
37 Correct 298 ms 20572 KB Output is correct
38 Correct 296 ms 20588 KB Output is correct
39 Correct 327 ms 20588 KB Output is correct
40 Correct 312 ms 20588 KB Output is correct
41 Correct 319 ms 20800 KB Output is correct
42 Correct 317 ms 20588 KB Output is correct
43 Correct 307 ms 20716 KB Output is correct
44 Correct 297 ms 20560 KB Output is correct
45 Correct 294 ms 20588 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 305 ms 20588 KB Output is correct
48 Correct 330 ms 20588 KB Output is correct
49 Correct 296 ms 20588 KB Output is correct
50 Correct 298 ms 20736 KB Output is correct
51 Correct 296 ms 20588 KB Output is correct
52 Correct 307 ms 20628 KB Output is correct
53 Correct 311 ms 20716 KB Output is correct
54 Correct 318 ms 20588 KB Output is correct
55 Correct 296 ms 20588 KB Output is correct
56 Correct 294 ms 20716 KB Output is correct
57 Correct 304 ms 20716 KB Output is correct
58 Correct 292 ms 20576 KB Output is correct
59 Correct 293 ms 20704 KB Output is correct
60 Correct 312 ms 20560 KB Output is correct
61 Correct 290 ms 20588 KB Output is correct
62 Correct 315 ms 20552 KB Output is correct
63 Correct 311 ms 20588 KB Output is correct
64 Correct 295 ms 20768 KB Output is correct
65 Correct 297 ms 20548 KB Output is correct
66 Correct 286 ms 20716 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 2 ms 492 KB Output is correct
69 Correct 2 ms 492 KB Output is correct
70 Correct 2 ms 492 KB Output is correct
71 Correct 2 ms 492 KB Output is correct
72 Correct 2 ms 492 KB Output is correct
73 Correct 2 ms 492 KB Output is correct
74 Correct 2 ms 492 KB Output is correct
75 Correct 2 ms 492 KB Output is correct
76 Correct 2 ms 492 KB Output is correct
77 Correct 2 ms 492 KB Output is correct
78 Correct 2 ms 492 KB Output is correct
79 Correct 2 ms 492 KB Output is correct
80 Correct 3 ms 492 KB Output is correct
81 Incorrect 1 ms 364 KB Output isn't correct
82 Halted 0 ms 0 KB -