Submission #368049

# Submission time Handle Problem Language Result Execution time Memory
368049 2021-02-19T11:52:22 Z ncduy0303 Cryptography (NOI20_crypto) C++17
35 / 100
321 ms 23404 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]));
        // 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();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory 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 384 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 0 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 384 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 384 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 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 308 ms 23288 KB Output is correct
3 Correct 306 ms 23148 KB Output is correct
4 Correct 307 ms 23276 KB Output is correct
5 Correct 303 ms 23148 KB Output is correct
6 Correct 298 ms 23148 KB Output is correct
7 Correct 314 ms 23148 KB Output is correct
8 Correct 319 ms 23404 KB Output is correct
9 Correct 313 ms 23148 KB Output is correct
10 Correct 317 ms 23148 KB Output is correct
11 Correct 321 ms 23148 KB Output is correct
12 Correct 307 ms 23276 KB Output is correct
13 Correct 304 ms 23148 KB Output is correct
14 Correct 308 ms 23276 KB Output is correct
15 Correct 318 ms 23148 KB Output is correct
16 Correct 314 ms 23148 KB Output is correct
17 Correct 314 ms 23276 KB Output is correct
18 Correct 311 ms 23148 KB Output is correct
19 Correct 302 ms 23148 KB Output is correct
20 Correct 311 ms 23148 KB Output is correct
21 Correct 301 ms 23148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 291 ms 22380 KB Output is correct
3 Correct 298 ms 22252 KB Output is correct
4 Correct 296 ms 22268 KB Output is correct
5 Correct 290 ms 22252 KB Output is correct
6 Correct 290 ms 22380 KB Output is correct
7 Correct 304 ms 22252 KB Output is correct
8 Correct 301 ms 22380 KB Output is correct
9 Correct 306 ms 22404 KB Output is correct
10 Correct 317 ms 22240 KB Output is correct
11 Correct 297 ms 22400 KB Output is correct
12 Correct 298 ms 22252 KB Output is correct
13 Correct 286 ms 22400 KB Output is correct
14 Correct 287 ms 22252 KB Output is correct
15 Correct 294 ms 22508 KB Output is correct
16 Correct 289 ms 22252 KB Output is correct
17 Correct 286 ms 22380 KB Output is correct
18 Correct 289 ms 22252 KB Output is correct
19 Correct 292 ms 22252 KB Output is correct
20 Correct 299 ms 22296 KB Output is correct
21 Correct 290 ms 22380 KB Output is correct
# Verdict Execution time Memory 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 2 ms 492 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 384 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 0 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 384 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 384 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 0 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 2 ms 492 KB Output is correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 291 ms 22380 KB Output is correct
3 Correct 298 ms 22252 KB Output is correct
4 Correct 296 ms 22268 KB Output is correct
5 Correct 290 ms 22252 KB Output is correct
6 Correct 290 ms 22380 KB Output is correct
7 Correct 304 ms 22252 KB Output is correct
8 Correct 301 ms 22380 KB Output is correct
9 Correct 306 ms 22404 KB Output is correct
10 Correct 317 ms 22240 KB Output is correct
11 Correct 297 ms 22400 KB Output is correct
12 Correct 298 ms 22252 KB Output is correct
13 Correct 286 ms 22400 KB Output is correct
14 Correct 287 ms 22252 KB Output is correct
15 Correct 294 ms 22508 KB Output is correct
16 Correct 289 ms 22252 KB Output is correct
17 Correct 286 ms 22380 KB Output is correct
18 Correct 289 ms 22252 KB Output is correct
19 Correct 292 ms 22252 KB Output is correct
20 Correct 299 ms 22296 KB Output is correct
21 Correct 290 ms 22380 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 2 ms 492 KB Output is correct
36 Incorrect 1 ms 364 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 384 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 0 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 384 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 384 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 0 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 308 ms 23288 KB Output is correct
27 Correct 306 ms 23148 KB Output is correct
28 Correct 307 ms 23276 KB Output is correct
29 Correct 303 ms 23148 KB Output is correct
30 Correct 298 ms 23148 KB Output is correct
31 Correct 314 ms 23148 KB Output is correct
32 Correct 319 ms 23404 KB Output is correct
33 Correct 313 ms 23148 KB Output is correct
34 Correct 317 ms 23148 KB Output is correct
35 Correct 321 ms 23148 KB Output is correct
36 Correct 307 ms 23276 KB Output is correct
37 Correct 304 ms 23148 KB Output is correct
38 Correct 308 ms 23276 KB Output is correct
39 Correct 318 ms 23148 KB Output is correct
40 Correct 314 ms 23148 KB Output is correct
41 Correct 314 ms 23276 KB Output is correct
42 Correct 311 ms 23148 KB Output is correct
43 Correct 302 ms 23148 KB Output is correct
44 Correct 311 ms 23148 KB Output is correct
45 Correct 301 ms 23148 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 291 ms 22380 KB Output is correct
48 Correct 298 ms 22252 KB Output is correct
49 Correct 296 ms 22268 KB Output is correct
50 Correct 290 ms 22252 KB Output is correct
51 Correct 290 ms 22380 KB Output is correct
52 Correct 304 ms 22252 KB Output is correct
53 Correct 301 ms 22380 KB Output is correct
54 Correct 306 ms 22404 KB Output is correct
55 Correct 317 ms 22240 KB Output is correct
56 Correct 297 ms 22400 KB Output is correct
57 Correct 298 ms 22252 KB Output is correct
58 Correct 286 ms 22400 KB Output is correct
59 Correct 287 ms 22252 KB Output is correct
60 Correct 294 ms 22508 KB Output is correct
61 Correct 289 ms 22252 KB Output is correct
62 Correct 286 ms 22380 KB Output is correct
63 Correct 289 ms 22252 KB Output is correct
64 Correct 292 ms 22252 KB Output is correct
65 Correct 299 ms 22296 KB Output is correct
66 Correct 290 ms 22380 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 2 ms 492 KB Output is correct
81 Incorrect 1 ms 364 KB Output isn't correct
82 Halted 0 ms 0 KB -