Submission #830157

# Submission time Handle Problem Language Result Execution time Memory
830157 2023-08-18T20:31:03 Z NK_ Cryptography (NOI20_crypto) C++17
100 / 100
474 ms 22128 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;
 
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;

const ll MOD = 1e9 + 7;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	

	int N; cin >> N;
	vl fact = {1}; for(int i = 1; i < N; i++) fact.pb((fact.back() * 1LL * i) % MOD);

	vi A(N); for(auto& x : A) cin >> x;

	vi X = A; sort(begin(X), end(X));
	for(auto& x : A) x = lower_bound(begin(X), end(X), x) - begin(X);

	iset<int> have; for(int i = 0; i < N; i++) have.insert(i);

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		ll l = have.order_of_key(A[i]);
		// cout << l << endl;

		ans += (l * 1LL * fact[N - 1 - i]) % MOD;
		ans %= MOD;

		have.erase(A[i]);
	}

	cout << (ans + 1) % MOD << nl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 307 ms 18972 KB Output is correct
3 Correct 304 ms 21992 KB Output is correct
4 Correct 303 ms 21964 KB Output is correct
5 Correct 312 ms 21900 KB Output is correct
6 Correct 310 ms 21988 KB Output is correct
7 Correct 280 ms 22012 KB Output is correct
8 Correct 287 ms 21960 KB Output is correct
9 Correct 280 ms 21884 KB Output is correct
10 Correct 284 ms 21992 KB Output is correct
11 Correct 324 ms 21900 KB Output is correct
12 Correct 314 ms 22004 KB Output is correct
13 Correct 303 ms 22000 KB Output is correct
14 Correct 312 ms 21944 KB Output is correct
15 Correct 286 ms 22076 KB Output is correct
16 Correct 288 ms 21944 KB Output is correct
17 Correct 293 ms 22108 KB Output is correct
18 Correct 295 ms 22012 KB Output is correct
19 Correct 307 ms 22008 KB Output is correct
20 Correct 304 ms 22016 KB Output is correct
21 Correct 307 ms 21944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 281 ms 19176 KB Output is correct
3 Correct 273 ms 19096 KB Output is correct
4 Correct 289 ms 19104 KB Output is correct
5 Correct 291 ms 19096 KB Output is correct
6 Correct 284 ms 18984 KB Output is correct
7 Correct 274 ms 19008 KB Output is correct
8 Correct 280 ms 19088 KB Output is correct
9 Correct 283 ms 19128 KB Output is correct
10 Correct 285 ms 19200 KB Output is correct
11 Correct 281 ms 19104 KB Output is correct
12 Correct 290 ms 19256 KB Output is correct
13 Correct 283 ms 19108 KB Output is correct
14 Correct 279 ms 19100 KB Output is correct
15 Correct 283 ms 18996 KB Output is correct
16 Correct 288 ms 19104 KB Output is correct
17 Correct 285 ms 19104 KB Output is correct
18 Correct 278 ms 19104 KB Output is correct
19 Correct 290 ms 19100 KB Output is correct
20 Correct 273 ms 19408 KB Output is correct
21 Correct 283 ms 18996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 456 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 456 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 3 ms 496 KB Output is correct
53 Correct 2 ms 540 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 2 ms 456 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 2 ms 436 KB Output is correct
68 Correct 2 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 281 ms 19176 KB Output is correct
3 Correct 273 ms 19096 KB Output is correct
4 Correct 289 ms 19104 KB Output is correct
5 Correct 291 ms 19096 KB Output is correct
6 Correct 284 ms 18984 KB Output is correct
7 Correct 274 ms 19008 KB Output is correct
8 Correct 280 ms 19088 KB Output is correct
9 Correct 283 ms 19128 KB Output is correct
10 Correct 285 ms 19200 KB Output is correct
11 Correct 281 ms 19104 KB Output is correct
12 Correct 290 ms 19256 KB Output is correct
13 Correct 283 ms 19108 KB Output is correct
14 Correct 279 ms 19100 KB Output is correct
15 Correct 283 ms 18996 KB Output is correct
16 Correct 288 ms 19104 KB Output is correct
17 Correct 285 ms 19104 KB Output is correct
18 Correct 278 ms 19104 KB Output is correct
19 Correct 290 ms 19100 KB Output is correct
20 Correct 273 ms 19408 KB Output is correct
21 Correct 283 ms 18996 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 3 ms 464 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 456 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 446 ms 21044 KB Output is correct
46 Correct 430 ms 20972 KB Output is correct
47 Correct 417 ms 21040 KB Output is correct
48 Correct 418 ms 21044 KB Output is correct
49 Correct 437 ms 21044 KB Output is correct
50 Correct 420 ms 20956 KB Output is correct
51 Correct 421 ms 20984 KB Output is correct
52 Correct 431 ms 21016 KB Output is correct
53 Correct 439 ms 21048 KB Output is correct
54 Correct 427 ms 21008 KB Output is correct
55 Correct 433 ms 20936 KB Output is correct
56 Correct 418 ms 21048 KB Output is correct
57 Correct 446 ms 21048 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 426 ms 20964 KB Output is correct
60 Correct 434 ms 21088 KB Output is correct
61 Correct 437 ms 21044 KB Output is correct
62 Correct 432 ms 21004 KB Output is correct
63 Correct 422 ms 20988 KB Output is correct
64 Correct 422 ms 21048 KB Output is correct
65 Correct 420 ms 20928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 307 ms 18972 KB Output is correct
27 Correct 304 ms 21992 KB Output is correct
28 Correct 303 ms 21964 KB Output is correct
29 Correct 312 ms 21900 KB Output is correct
30 Correct 310 ms 21988 KB Output is correct
31 Correct 280 ms 22012 KB Output is correct
32 Correct 287 ms 21960 KB Output is correct
33 Correct 280 ms 21884 KB Output is correct
34 Correct 284 ms 21992 KB Output is correct
35 Correct 324 ms 21900 KB Output is correct
36 Correct 314 ms 22004 KB Output is correct
37 Correct 303 ms 22000 KB Output is correct
38 Correct 312 ms 21944 KB Output is correct
39 Correct 286 ms 22076 KB Output is correct
40 Correct 288 ms 21944 KB Output is correct
41 Correct 293 ms 22108 KB Output is correct
42 Correct 295 ms 22012 KB Output is correct
43 Correct 307 ms 22008 KB Output is correct
44 Correct 304 ms 22016 KB Output is correct
45 Correct 307 ms 21944 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 281 ms 19176 KB Output is correct
48 Correct 273 ms 19096 KB Output is correct
49 Correct 289 ms 19104 KB Output is correct
50 Correct 291 ms 19096 KB Output is correct
51 Correct 284 ms 18984 KB Output is correct
52 Correct 274 ms 19008 KB Output is correct
53 Correct 280 ms 19088 KB Output is correct
54 Correct 283 ms 19128 KB Output is correct
55 Correct 285 ms 19200 KB Output is correct
56 Correct 281 ms 19104 KB Output is correct
57 Correct 290 ms 19256 KB Output is correct
58 Correct 283 ms 19108 KB Output is correct
59 Correct 279 ms 19100 KB Output is correct
60 Correct 283 ms 18996 KB Output is correct
61 Correct 288 ms 19104 KB Output is correct
62 Correct 285 ms 19104 KB Output is correct
63 Correct 278 ms 19104 KB Output is correct
64 Correct 290 ms 19100 KB Output is correct
65 Correct 273 ms 19408 KB Output is correct
66 Correct 283 ms 18996 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 2 ms 468 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 2 ms 468 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 3 ms 464 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 2 ms 456 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 2 ms 468 KB Output is correct
78 Correct 2 ms 468 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 0 ms 212 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 2 ms 468 KB Output is correct
87 Correct 2 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 2 ms 468 KB Output is correct
91 Correct 2 ms 468 KB Output is correct
92 Correct 2 ms 456 KB Output is correct
93 Correct 2 ms 468 KB Output is correct
94 Correct 3 ms 496 KB Output is correct
95 Correct 2 ms 540 KB Output is correct
96 Correct 2 ms 468 KB Output is correct
97 Correct 2 ms 468 KB Output is correct
98 Correct 2 ms 468 KB Output is correct
99 Correct 2 ms 468 KB Output is correct
100 Correct 2 ms 468 KB Output is correct
101 Correct 2 ms 468 KB Output is correct
102 Correct 2 ms 468 KB Output is correct
103 Correct 0 ms 212 KB Output is correct
104 Correct 2 ms 468 KB Output is correct
105 Correct 2 ms 468 KB Output is correct
106 Correct 2 ms 468 KB Output is correct
107 Correct 2 ms 456 KB Output is correct
108 Correct 2 ms 468 KB Output is correct
109 Correct 2 ms 436 KB Output is correct
110 Correct 2 ms 540 KB Output is correct
111 Correct 0 ms 212 KB Output is correct
112 Correct 446 ms 21044 KB Output is correct
113 Correct 430 ms 20972 KB Output is correct
114 Correct 417 ms 21040 KB Output is correct
115 Correct 418 ms 21044 KB Output is correct
116 Correct 437 ms 21044 KB Output is correct
117 Correct 420 ms 20956 KB Output is correct
118 Correct 421 ms 20984 KB Output is correct
119 Correct 431 ms 21016 KB Output is correct
120 Correct 439 ms 21048 KB Output is correct
121 Correct 427 ms 21008 KB Output is correct
122 Correct 433 ms 20936 KB Output is correct
123 Correct 418 ms 21048 KB Output is correct
124 Correct 446 ms 21048 KB Output is correct
125 Correct 0 ms 212 KB Output is correct
126 Correct 426 ms 20964 KB Output is correct
127 Correct 434 ms 21088 KB Output is correct
128 Correct 437 ms 21044 KB Output is correct
129 Correct 432 ms 21004 KB Output is correct
130 Correct 422 ms 20988 KB Output is correct
131 Correct 422 ms 21048 KB Output is correct
132 Correct 420 ms 20928 KB Output is correct
133 Correct 1 ms 212 KB Output is correct
134 Correct 423 ms 21948 KB Output is correct
135 Correct 433 ms 22020 KB Output is correct
136 Correct 424 ms 21944 KB Output is correct
137 Correct 421 ms 21964 KB Output is correct
138 Correct 425 ms 21944 KB Output is correct
139 Correct 424 ms 22028 KB Output is correct
140 Correct 426 ms 21944 KB Output is correct
141 Correct 420 ms 21892 KB Output is correct
142 Correct 439 ms 22012 KB Output is correct
143 Correct 422 ms 21908 KB Output is correct
144 Correct 438 ms 21944 KB Output is correct
145 Correct 423 ms 21996 KB Output is correct
146 Correct 425 ms 22128 KB Output is correct
147 Correct 1 ms 212 KB Output is correct
148 Correct 431 ms 22000 KB Output is correct
149 Correct 426 ms 22000 KB Output is correct
150 Correct 423 ms 21880 KB Output is correct
151 Correct 417 ms 21944 KB Output is correct
152 Correct 435 ms 21964 KB Output is correct
153 Correct 427 ms 21900 KB Output is correct
154 Correct 474 ms 22076 KB Output is correct