/**
* author: Haunted_Cpp
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const int MAX_N = 3e5 + 5;
const int MOD = 1e9 + 7;
int f[MAX_N], bit[MAX_N];
void update(int idx, int delta) {
for (; idx < MAX_N; idx += idx & (- idx)) {
bit[idx] += delta;
}
}
int query(int idx) {
int res = 0;
for (; idx > 0; idx -= idx & (- idx)) {
res += bit[idx];
}
return res;
}
int add(int a, int b) {
int res = a + b;
if (res >= MOD) res += MOD;
if (res < 0) res += MOD;
return res;
}
int mult(int a, int b) {
long long res = 1LL * a * b;
if (res >= MOD) res %= MOD;
return res;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> arr(n);
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
c[i] = arr[i];
}
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
for (auto &to : arr) {
to = lower_bound(c.begin(), c.end(), to) - c.begin() + 1;
update(to, +1);
}
f[0] = 1;
for (int i = 1; i < MAX_N; i++) {
f[i] = mult(f[i - 1], i);
}
int res = 0;
int left = n - 1;
for (int i = 0; i < n; left--, i++) {
int l = query(arr[i] - 1);
res = add(res, mult(l, f[left]));
update(arr[i], -1);
}
cout << add(res, +1) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
4 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
3 ms |
1536 KB |
Output is correct |
8 |
Correct |
3 ms |
1536 KB |
Output is correct |
9 |
Correct |
3 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1536 KB |
Output is correct |
11 |
Correct |
3 ms |
1536 KB |
Output is correct |
12 |
Correct |
3 ms |
1536 KB |
Output is correct |
13 |
Correct |
3 ms |
1536 KB |
Output is correct |
14 |
Correct |
3 ms |
1536 KB |
Output is correct |
15 |
Correct |
3 ms |
1536 KB |
Output is correct |
16 |
Correct |
3 ms |
1536 KB |
Output is correct |
17 |
Correct |
3 ms |
1536 KB |
Output is correct |
18 |
Correct |
3 ms |
1536 KB |
Output is correct |
19 |
Correct |
3 ms |
1536 KB |
Output is correct |
20 |
Correct |
3 ms |
1536 KB |
Output is correct |
21 |
Correct |
3 ms |
1536 KB |
Output is correct |
22 |
Correct |
3 ms |
1536 KB |
Output is correct |
23 |
Correct |
3 ms |
1536 KB |
Output is correct |
24 |
Correct |
3 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Incorrect |
93 ms |
7976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
82 ms |
7032 KB |
Output is correct |
3 |
Correct |
83 ms |
7032 KB |
Output is correct |
4 |
Correct |
84 ms |
6904 KB |
Output is correct |
5 |
Correct |
85 ms |
7000 KB |
Output is correct |
6 |
Correct |
84 ms |
7032 KB |
Output is correct |
7 |
Correct |
83 ms |
7032 KB |
Output is correct |
8 |
Correct |
83 ms |
6904 KB |
Output is correct |
9 |
Correct |
84 ms |
7032 KB |
Output is correct |
10 |
Correct |
83 ms |
7032 KB |
Output is correct |
11 |
Correct |
84 ms |
6904 KB |
Output is correct |
12 |
Correct |
83 ms |
7160 KB |
Output is correct |
13 |
Correct |
83 ms |
7032 KB |
Output is correct |
14 |
Correct |
83 ms |
6904 KB |
Output is correct |
15 |
Correct |
84 ms |
7032 KB |
Output is correct |
16 |
Correct |
82 ms |
7160 KB |
Output is correct |
17 |
Correct |
84 ms |
7032 KB |
Output is correct |
18 |
Correct |
85 ms |
7032 KB |
Output is correct |
19 |
Correct |
83 ms |
7032 KB |
Output is correct |
20 |
Correct |
83 ms |
7032 KB |
Output is correct |
21 |
Correct |
83 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
4 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
3 ms |
1536 KB |
Output is correct |
8 |
Correct |
3 ms |
1536 KB |
Output is correct |
9 |
Correct |
3 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1536 KB |
Output is correct |
11 |
Correct |
3 ms |
1536 KB |
Output is correct |
12 |
Correct |
3 ms |
1536 KB |
Output is correct |
13 |
Correct |
3 ms |
1536 KB |
Output is correct |
14 |
Correct |
3 ms |
1536 KB |
Output is correct |
15 |
Correct |
3 ms |
1536 KB |
Output is correct |
16 |
Correct |
3 ms |
1536 KB |
Output is correct |
17 |
Correct |
3 ms |
1536 KB |
Output is correct |
18 |
Correct |
3 ms |
1536 KB |
Output is correct |
19 |
Correct |
3 ms |
1536 KB |
Output is correct |
20 |
Correct |
3 ms |
1536 KB |
Output is correct |
21 |
Correct |
3 ms |
1536 KB |
Output is correct |
22 |
Correct |
3 ms |
1536 KB |
Output is correct |
23 |
Correct |
3 ms |
1536 KB |
Output is correct |
24 |
Correct |
3 ms |
1536 KB |
Output is correct |
25 |
Correct |
3 ms |
1536 KB |
Output is correct |
26 |
Incorrect |
4 ms |
1536 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
82 ms |
7032 KB |
Output is correct |
3 |
Correct |
83 ms |
7032 KB |
Output is correct |
4 |
Correct |
84 ms |
6904 KB |
Output is correct |
5 |
Correct |
85 ms |
7000 KB |
Output is correct |
6 |
Correct |
84 ms |
7032 KB |
Output is correct |
7 |
Correct |
83 ms |
7032 KB |
Output is correct |
8 |
Correct |
83 ms |
6904 KB |
Output is correct |
9 |
Correct |
84 ms |
7032 KB |
Output is correct |
10 |
Correct |
83 ms |
7032 KB |
Output is correct |
11 |
Correct |
84 ms |
6904 KB |
Output is correct |
12 |
Correct |
83 ms |
7160 KB |
Output is correct |
13 |
Correct |
83 ms |
7032 KB |
Output is correct |
14 |
Correct |
83 ms |
6904 KB |
Output is correct |
15 |
Correct |
84 ms |
7032 KB |
Output is correct |
16 |
Correct |
82 ms |
7160 KB |
Output is correct |
17 |
Correct |
84 ms |
7032 KB |
Output is correct |
18 |
Correct |
85 ms |
7032 KB |
Output is correct |
19 |
Correct |
83 ms |
7032 KB |
Output is correct |
20 |
Correct |
83 ms |
7032 KB |
Output is correct |
21 |
Correct |
83 ms |
6904 KB |
Output is correct |
22 |
Correct |
3 ms |
1536 KB |
Output is correct |
23 |
Incorrect |
4 ms |
1536 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
4 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
3 ms |
1536 KB |
Output is correct |
8 |
Correct |
3 ms |
1536 KB |
Output is correct |
9 |
Correct |
3 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1536 KB |
Output is correct |
11 |
Correct |
3 ms |
1536 KB |
Output is correct |
12 |
Correct |
3 ms |
1536 KB |
Output is correct |
13 |
Correct |
3 ms |
1536 KB |
Output is correct |
14 |
Correct |
3 ms |
1536 KB |
Output is correct |
15 |
Correct |
3 ms |
1536 KB |
Output is correct |
16 |
Correct |
3 ms |
1536 KB |
Output is correct |
17 |
Correct |
3 ms |
1536 KB |
Output is correct |
18 |
Correct |
3 ms |
1536 KB |
Output is correct |
19 |
Correct |
3 ms |
1536 KB |
Output is correct |
20 |
Correct |
3 ms |
1536 KB |
Output is correct |
21 |
Correct |
3 ms |
1536 KB |
Output is correct |
22 |
Correct |
3 ms |
1536 KB |
Output is correct |
23 |
Correct |
3 ms |
1536 KB |
Output is correct |
24 |
Correct |
3 ms |
1536 KB |
Output is correct |
25 |
Correct |
3 ms |
1536 KB |
Output is correct |
26 |
Incorrect |
93 ms |
7976 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |