Submission #504589

# Submission time Handle Problem Language Result Execution time Memory
504589 2022-01-10T06:39:29 Z Jomnoi Cryptography (NOI20_crypto) C++17
100 / 100
621 ms 36220 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;

int p[N];
map <int, int> cmp;
int fenwick[N];
long long fac[N];

void update(int idx, int val) {
    for(; idx < N; idx += (idx & -idx)) {
        fenwick[idx] += val;
    }
}

int query(int idx) {
    int res = 0;
    for(; idx > 0; idx -= (idx & -idx)) {
        res += fenwick[idx];
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    fac[0] = 1;
    for(int i = 1; i <= n; i++) {
        fac[i] = fac[i - 1] * i % MOD;
    }

    set <int> s;
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
        s.insert(p[i]);
    }

    int cnt = 0;
    for(auto v : s) {
        cmp[v] = ++cnt;
    }

    long long ans = 1;
    for(int i = 1; i <= n; i++) {
        ans = (ans + fac[n - i] * (cmp[p[i]] - query(cmp[p[i]]) - 1) % MOD) % MOD;
        update(cmp[p[i]], 1);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 295 ms 36016 KB Output is correct
3 Correct 258 ms 36004 KB Output is correct
4 Correct 274 ms 36024 KB Output is correct
5 Correct 302 ms 35996 KB Output is correct
6 Correct 273 ms 36060 KB Output is correct
7 Correct 282 ms 35988 KB Output is correct
8 Correct 273 ms 36080 KB Output is correct
9 Correct 341 ms 35968 KB Output is correct
10 Correct 291 ms 36060 KB Output is correct
11 Correct 287 ms 36092 KB Output is correct
12 Correct 273 ms 35968 KB Output is correct
13 Correct 276 ms 36168 KB Output is correct
14 Correct 274 ms 36028 KB Output is correct
15 Correct 270 ms 36028 KB Output is correct
16 Correct 267 ms 36068 KB Output is correct
17 Correct 262 ms 36124 KB Output is correct
18 Correct 269 ms 36012 KB Output is correct
19 Correct 262 ms 36052 KB Output is correct
20 Correct 267 ms 36016 KB Output is correct
21 Correct 298 ms 36052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 261 ms 35088 KB Output is correct
3 Correct 247 ms 35056 KB Output is correct
4 Correct 257 ms 35008 KB Output is correct
5 Correct 244 ms 35124 KB Output is correct
6 Correct 259 ms 35012 KB Output is correct
7 Correct 243 ms 35064 KB Output is correct
8 Correct 255 ms 35120 KB Output is correct
9 Correct 245 ms 35156 KB Output is correct
10 Correct 261 ms 35016 KB Output is correct
11 Correct 261 ms 35040 KB Output is correct
12 Correct 280 ms 35004 KB Output is correct
13 Correct 243 ms 35120 KB Output is correct
14 Correct 265 ms 35116 KB Output is correct
15 Correct 289 ms 35056 KB Output is correct
16 Correct 238 ms 35096 KB Output is correct
17 Correct 287 ms 35220 KB Output is correct
18 Correct 243 ms 35040 KB Output is correct
19 Correct 242 ms 35012 KB Output is correct
20 Correct 305 ms 35068 KB Output is correct
21 Correct 252 ms 35092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 696 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 4 ms 588 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 4 ms 588 KB Output is correct
32 Correct 4 ms 716 KB Output is correct
33 Correct 2 ms 588 KB Output is correct
34 Correct 3 ms 572 KB Output is correct
35 Correct 3 ms 588 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 696 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 2 ms 612 KB Output is correct
44 Correct 2 ms 600 KB Output is correct
45 Correct 3 ms 600 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 3 ms 716 KB Output is correct
49 Correct 2 ms 600 KB Output is correct
50 Correct 3 ms 688 KB Output is correct
51 Correct 3 ms 716 KB Output is correct
52 Correct 4 ms 716 KB Output is correct
53 Correct 3 ms 600 KB Output is correct
54 Correct 3 ms 716 KB Output is correct
55 Correct 3 ms 716 KB Output is correct
56 Correct 3 ms 716 KB Output is correct
57 Correct 3 ms 712 KB Output is correct
58 Correct 3 ms 716 KB Output is correct
59 Correct 2 ms 600 KB Output is correct
60 Correct 4 ms 716 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 3 ms 716 KB Output is correct
63 Correct 2 ms 716 KB Output is correct
64 Correct 3 ms 600 KB Output is correct
65 Correct 2 ms 716 KB Output is correct
66 Correct 2 ms 716 KB Output is correct
67 Correct 2 ms 716 KB Output is correct
68 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 261 ms 35088 KB Output is correct
3 Correct 247 ms 35056 KB Output is correct
4 Correct 257 ms 35008 KB Output is correct
5 Correct 244 ms 35124 KB Output is correct
6 Correct 259 ms 35012 KB Output is correct
7 Correct 243 ms 35064 KB Output is correct
8 Correct 255 ms 35120 KB Output is correct
9 Correct 245 ms 35156 KB Output is correct
10 Correct 261 ms 35016 KB Output is correct
11 Correct 261 ms 35040 KB Output is correct
12 Correct 280 ms 35004 KB Output is correct
13 Correct 243 ms 35120 KB Output is correct
14 Correct 265 ms 35116 KB Output is correct
15 Correct 289 ms 35056 KB Output is correct
16 Correct 238 ms 35096 KB Output is correct
17 Correct 287 ms 35220 KB Output is correct
18 Correct 243 ms 35040 KB Output is correct
19 Correct 242 ms 35012 KB Output is correct
20 Correct 305 ms 35068 KB Output is correct
21 Correct 252 ms 35092 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 4 ms 588 KB Output is correct
29 Correct 4 ms 716 KB Output is correct
30 Correct 2 ms 588 KB Output is correct
31 Correct 3 ms 572 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 588 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 2 ms 588 KB Output is correct
38 Correct 2 ms 696 KB Output is correct
39 Correct 3 ms 716 KB Output is correct
40 Correct 2 ms 612 KB Output is correct
41 Correct 2 ms 600 KB Output is correct
42 Correct 3 ms 600 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 594 ms 35120 KB Output is correct
46 Correct 555 ms 35020 KB Output is correct
47 Correct 588 ms 35240 KB Output is correct
48 Correct 565 ms 35116 KB Output is correct
49 Correct 517 ms 35040 KB Output is correct
50 Correct 557 ms 35132 KB Output is correct
51 Correct 552 ms 35108 KB Output is correct
52 Correct 578 ms 35116 KB Output is correct
53 Correct 551 ms 35116 KB Output is correct
54 Correct 585 ms 35116 KB Output is correct
55 Correct 524 ms 35120 KB Output is correct
56 Correct 520 ms 35128 KB Output is correct
57 Correct 564 ms 35104 KB Output is correct
58 Correct 0 ms 288 KB Output is correct
59 Correct 599 ms 35120 KB Output is correct
60 Correct 511 ms 35108 KB Output is correct
61 Correct 527 ms 35116 KB Output is correct
62 Correct 557 ms 35060 KB Output is correct
63 Correct 585 ms 35120 KB Output is correct
64 Correct 600 ms 35204 KB Output is correct
65 Correct 571 ms 35116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 295 ms 36016 KB Output is correct
27 Correct 258 ms 36004 KB Output is correct
28 Correct 274 ms 36024 KB Output is correct
29 Correct 302 ms 35996 KB Output is correct
30 Correct 273 ms 36060 KB Output is correct
31 Correct 282 ms 35988 KB Output is correct
32 Correct 273 ms 36080 KB Output is correct
33 Correct 341 ms 35968 KB Output is correct
34 Correct 291 ms 36060 KB Output is correct
35 Correct 287 ms 36092 KB Output is correct
36 Correct 273 ms 35968 KB Output is correct
37 Correct 276 ms 36168 KB Output is correct
38 Correct 274 ms 36028 KB Output is correct
39 Correct 270 ms 36028 KB Output is correct
40 Correct 267 ms 36068 KB Output is correct
41 Correct 262 ms 36124 KB Output is correct
42 Correct 269 ms 36012 KB Output is correct
43 Correct 262 ms 36052 KB Output is correct
44 Correct 267 ms 36016 KB Output is correct
45 Correct 298 ms 36052 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 261 ms 35088 KB Output is correct
48 Correct 247 ms 35056 KB Output is correct
49 Correct 257 ms 35008 KB Output is correct
50 Correct 244 ms 35124 KB Output is correct
51 Correct 259 ms 35012 KB Output is correct
52 Correct 243 ms 35064 KB Output is correct
53 Correct 255 ms 35120 KB Output is correct
54 Correct 245 ms 35156 KB Output is correct
55 Correct 261 ms 35016 KB Output is correct
56 Correct 261 ms 35040 KB Output is correct
57 Correct 280 ms 35004 KB Output is correct
58 Correct 243 ms 35120 KB Output is correct
59 Correct 265 ms 35116 KB Output is correct
60 Correct 289 ms 35056 KB Output is correct
61 Correct 238 ms 35096 KB Output is correct
62 Correct 287 ms 35220 KB Output is correct
63 Correct 243 ms 35040 KB Output is correct
64 Correct 242 ms 35012 KB Output is correct
65 Correct 305 ms 35068 KB Output is correct
66 Correct 252 ms 35092 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 4 ms 588 KB Output is correct
69 Correct 2 ms 588 KB Output is correct
70 Correct 2 ms 588 KB Output is correct
71 Correct 3 ms 600 KB Output is correct
72 Correct 2 ms 588 KB Output is correct
73 Correct 4 ms 588 KB Output is correct
74 Correct 4 ms 716 KB Output is correct
75 Correct 2 ms 588 KB Output is correct
76 Correct 3 ms 572 KB Output is correct
77 Correct 3 ms 588 KB Output is correct
78 Correct 2 ms 592 KB Output is correct
79 Correct 2 ms 588 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 0 ms 332 KB Output is correct
82 Correct 2 ms 588 KB Output is correct
83 Correct 2 ms 696 KB Output is correct
84 Correct 3 ms 716 KB Output is correct
85 Correct 2 ms 612 KB Output is correct
86 Correct 2 ms 600 KB Output is correct
87 Correct 3 ms 600 KB Output is correct
88 Correct 3 ms 640 KB Output is correct
89 Correct 0 ms 332 KB Output is correct
90 Correct 3 ms 716 KB Output is correct
91 Correct 2 ms 600 KB Output is correct
92 Correct 3 ms 688 KB Output is correct
93 Correct 3 ms 716 KB Output is correct
94 Correct 4 ms 716 KB Output is correct
95 Correct 3 ms 600 KB Output is correct
96 Correct 3 ms 716 KB Output is correct
97 Correct 3 ms 716 KB Output is correct
98 Correct 3 ms 716 KB Output is correct
99 Correct 3 ms 712 KB Output is correct
100 Correct 3 ms 716 KB Output is correct
101 Correct 2 ms 600 KB Output is correct
102 Correct 4 ms 716 KB Output is correct
103 Correct 0 ms 332 KB Output is correct
104 Correct 3 ms 716 KB Output is correct
105 Correct 2 ms 716 KB Output is correct
106 Correct 3 ms 600 KB Output is correct
107 Correct 2 ms 716 KB Output is correct
108 Correct 2 ms 716 KB Output is correct
109 Correct 2 ms 716 KB Output is correct
110 Correct 2 ms 672 KB Output is correct
111 Correct 1 ms 332 KB Output is correct
112 Correct 594 ms 35120 KB Output is correct
113 Correct 555 ms 35020 KB Output is correct
114 Correct 588 ms 35240 KB Output is correct
115 Correct 565 ms 35116 KB Output is correct
116 Correct 517 ms 35040 KB Output is correct
117 Correct 557 ms 35132 KB Output is correct
118 Correct 552 ms 35108 KB Output is correct
119 Correct 578 ms 35116 KB Output is correct
120 Correct 551 ms 35116 KB Output is correct
121 Correct 585 ms 35116 KB Output is correct
122 Correct 524 ms 35120 KB Output is correct
123 Correct 520 ms 35128 KB Output is correct
124 Correct 564 ms 35104 KB Output is correct
125 Correct 0 ms 288 KB Output is correct
126 Correct 599 ms 35120 KB Output is correct
127 Correct 511 ms 35108 KB Output is correct
128 Correct 527 ms 35116 KB Output is correct
129 Correct 557 ms 35060 KB Output is correct
130 Correct 585 ms 35120 KB Output is correct
131 Correct 600 ms 35204 KB Output is correct
132 Correct 571 ms 35116 KB Output is correct
133 Correct 0 ms 332 KB Output is correct
134 Correct 554 ms 36092 KB Output is correct
135 Correct 575 ms 36164 KB Output is correct
136 Correct 553 ms 36076 KB Output is correct
137 Correct 516 ms 36080 KB Output is correct
138 Correct 587 ms 36024 KB Output is correct
139 Correct 537 ms 36104 KB Output is correct
140 Correct 621 ms 36084 KB Output is correct
141 Correct 563 ms 36216 KB Output is correct
142 Correct 521 ms 36136 KB Output is correct
143 Correct 573 ms 36072 KB Output is correct
144 Correct 567 ms 36036 KB Output is correct
145 Correct 543 ms 36136 KB Output is correct
146 Correct 527 ms 36080 KB Output is correct
147 Correct 1 ms 332 KB Output is correct
148 Correct 618 ms 36072 KB Output is correct
149 Correct 546 ms 36080 KB Output is correct
150 Correct 569 ms 36080 KB Output is correct
151 Correct 578 ms 36220 KB Output is correct
152 Correct 583 ms 36076 KB Output is correct
153 Correct 551 ms 36080 KB Output is correct
154 Correct 603 ms 36080 KB Output is correct