Submission #830156

# Submission time Handle Problem Language Result Execution time Memory
830156 2023-08-18T20:28:55 Z NK_ Cryptography (NOI20_crypto) C++17
25 / 100
301 ms 19256 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;

		have.erase(A[i]);
	}

	cout << ans + 1 << nl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 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 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 Incorrect 301 ms 19076 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 288 ms 19088 KB Output is correct
3 Correct 283 ms 19100 KB Output is correct
4 Correct 272 ms 19104 KB Output is correct
5 Correct 279 ms 19192 KB Output is correct
6 Correct 278 ms 19088 KB Output is correct
7 Correct 284 ms 19000 KB Output is correct
8 Correct 282 ms 19096 KB Output is correct
9 Correct 277 ms 19072 KB Output is correct
10 Correct 281 ms 19256 KB Output is correct
11 Correct 279 ms 19084 KB Output is correct
12 Correct 282 ms 18976 KB Output is correct
13 Correct 280 ms 19176 KB Output is correct
14 Correct 276 ms 19000 KB Output is correct
15 Correct 275 ms 18988 KB Output is correct
16 Correct 280 ms 19104 KB Output is correct
17 Correct 286 ms 19104 KB Output is correct
18 Correct 278 ms 19192 KB Output is correct
19 Correct 278 ms 19104 KB Output is correct
20 Correct 283 ms 19008 KB Output is correct
21 Correct 273 ms 19000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 Incorrect 2 ms 468 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 288 ms 19088 KB Output is correct
3 Correct 283 ms 19100 KB Output is correct
4 Correct 272 ms 19104 KB Output is correct
5 Correct 279 ms 19192 KB Output is correct
6 Correct 278 ms 19088 KB Output is correct
7 Correct 284 ms 19000 KB Output is correct
8 Correct 282 ms 19096 KB Output is correct
9 Correct 277 ms 19072 KB Output is correct
10 Correct 281 ms 19256 KB Output is correct
11 Correct 279 ms 19084 KB Output is correct
12 Correct 282 ms 18976 KB Output is correct
13 Correct 280 ms 19176 KB Output is correct
14 Correct 276 ms 19000 KB Output is correct
15 Correct 275 ms 18988 KB Output is correct
16 Correct 280 ms 19104 KB Output is correct
17 Correct 286 ms 19104 KB Output is correct
18 Correct 278 ms 19192 KB Output is correct
19 Correct 278 ms 19104 KB Output is correct
20 Correct 283 ms 19008 KB Output is correct
21 Correct 273 ms 19000 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 2 ms 468 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 Incorrect 301 ms 19076 KB Output isn't correct
27 Halted 0 ms 0 KB -