QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#192427 | #7237. Sort it! | jeffqi# | AC ✓ | 109ms | 65888kb | C++20 | 1.8kb | 2023-09-30 14:31:01 | 2023-09-30 14:31:02 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;
namespace qiqi {
const int P = 1e9+7;
struct BIT {
int n; vll a; BIT(int n):n(n),a(n,0) {}
int lbt(int x) {return x&(-x);}
void upd(int x,int k) {
for (int i = x+1; i <= n; i += lbt(i)) {
a[i-1] = (a[i-1]+k)%P;
}
}
int qry(int x) {
ll k = 0;
for (int i = x; i > 0; i -= lbt(i)) {
k += a[i-1];
}
return k%P;
}
};
void main() {
int n;
cin >> n;
vi p(n);
for (int i = 0; i < n; i++) {
cin >> p[i]; p[i]--;
}
vector<BIT> bit(n+1,n+1);
bit[0].upd(0,1);
for (int i = 0; i < n; i++) {
for (int j = i; j >= 0; j--) {
bit[j+1].upd(p[i]+1,bit[j].qry(p[i]+1));
}
}
vector<vll> s(n+1,vll(n+1)); s[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
s[i][j] = (s[i-1][j-1]+j*s[i-1][j])%P;
}
}
vll fac(n+1); fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = i*fac[i-1]%P;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ll k = bit[i].qry(n+1);
ans = (ans+k*fac[i]%P*s[n][i])%P;
}
cout << ans << '\n';
}
}
int main() {
// clock_t st = clock();
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
qiqi::main();
}
// cout << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3416kb
input:
2 2 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
3 2 1 3
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
2 1 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
3 1 2 3
output:
27
result:
ok 1 number(s): "27"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
3 1 3 2
output:
15
result:
ok 1 number(s): "15"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 2 3 1
output:
9
result:
ok 1 number(s): "9"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
3 3 1 2
output:
9
result:
ok 1 number(s): "9"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
8 3 1 2 7 6 8 5 4
output:
149984
result:
ok 1 number(s): "149984"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
15 15 5 4 9 7 10 3 13 14 1 8 11 2 6 12
output:
600062423
result:
ok 1 number(s): "600062423"
Test #12:
score: 0
Accepted
time: 11ms
memory: 15632kb
input:
894 670 618 579 212 780 557 380 412 672 8 777 117 684 768 99 404 140 122 139 329 623 17 645 18 880 790 625 505 307 747 801 754 783 146 757 263 285 228 719 640 199 193 105 234 847 842 348 159 823 577 466 133 850 851 643 802 819 317 826 55 617 690 604 229 570 254 759 575 498 240 397 736 864 415 751 49...
output:
333399230
result:
ok 1 number(s): "333399230"
Test #13:
score: 0
Accepted
time: 2ms
memory: 4292kb
input:
271 267 262 148 36 96 73 257 70 18 200 103 201 77 88 54 126 178 172 56 171 105 10 125 102 79 255 218 260 64 249 107 16 83 121 222 205 217 184 244 120 190 2 63 183 196 215 149 37 179 127 168 247 233 41 23 67 110 71 14 81 57 157 241 162 143 85 122 195 98 101 151 221 243 39 91 203 3 154 62 137 251 6 15...
output:
385331618
result:
ok 1 number(s): "385331618"
Test #14:
score: 0
Accepted
time: 108ms
memory: 65888kb
input:
2000 381 165 79 257 1037 1970 548 536 1312 1164 460 1189 380 950 1666 1491 1300 49 1414 786 1201 1364 1236 1519 182 1662 1578 1228 298 427 1511 1409 518 595 378 1737 183 929 899 1674 262 992 1246 563 1138 544 541 1527 1634 1963 166 1337 1656 1405 1693 1969 68 528 229 310 322 1922 1000 371 623 1830 7...
output:
916831570
result:
ok 1 number(s): "916831570"
Test #15:
score: 0
Accepted
time: 103ms
memory: 65816kb
input:
2000 433 1306 1470 1177 891 333 237 26 1070 637 487 725 1222 133 826 1797 1213 351 1888 1272 1628 52 1691 1830 776 352 198 1788 1444 1187 1741 1709 1352 1388 1492 86 120 332 1844 113 1652 523 962 1858 1126 1765 1302 285 85 960 1529 1457 1344 1916 773 769 1729 387 129 649 1182 569 1209 51 1308 104 63...
output:
709731050
result:
ok 1 number(s): "709731050"
Test #16:
score: 0
Accepted
time: 109ms
memory: 65876kb
input:
2000 338 1210 597 105 357 82 928 1879 1760 341 1961 1445 1169 1832 1460 1791 1597 1315 1270 744 1344 1511 599 90 349 811 125 840 1935 1711 995 1002 159 1769 859 1754 889 751 1186 1336 1496 1092 413 405 1077 586 705 150 567 426 1357 180 1404 138 668 825 36 276 133 333 1590 1265 830 873 1453 1949 1520...
output:
499882073
result:
ok 1 number(s): "499882073"
Test #17:
score: 0
Accepted
time: 51ms
memory: 65860kb
input:
2000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
596636543
result:
ok 1 number(s): "596636543"
Test #18:
score: 0
Accepted
time: 54ms
memory: 65804kb
input:
2000 1 2 1192 4 5 6 7 8 9 10 11 12 13 14 15 16 336 18 19 20 341 22 23 24 25 1396 1558 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 187 55 56 57 58 975 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 1551 80 81 82 83 124 85 86 1412 88 89 90 1966 92 93 94 95 9...
output:
336718679
result:
ok 1 number(s): "336718679"
Test #19:
score: 0
Accepted
time: 74ms
memory: 65804kb
input:
2000 1 2 3 4 5 6 7 1330 9 10 11 12 13 14 15 16 374 1423 19 20 498 22 515 44 390 26 726 28 944 30 31 32 33 186 35 36 37 38 988 40 41 42 43 24 45 46 47 48 49 888 51 52 53 344 55 56 57 1944 59 60 61 62 63 1914 677 317 804 68 69 70 1939 1022 1550 74 75 76 77 78 79 80 81 67 691 84 1655 86 87 88 89 90 91 ...
output:
31673026
result:
ok 1 number(s): "31673026"
Test #20:
score: 0
Accepted
time: 55ms
memory: 65844kb
input:
2000 2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 1946 1945 1944 1943 1942 ...
output:
2000
result:
ok 1 number(s): "2000"
Test #21:
score: 0
Accepted
time: 66ms
memory: 65812kb
input:
2000 2000 1999 809 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1665 1983 1982 1981 1660 1979 1978 1977 1976 605 443 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1814 1946 1945 1944 1943 1026 194...
output:
424669338
result:
ok 1 number(s): "424669338"
Test #22:
score: 0
Accepted
time: 94ms
memory: 65796kb
input:
2000 2000 1999 1998 1997 1996 1995 1994 671 1992 1991 1990 1989 1988 1987 1986 1985 1627 578 1982 1981 1503 1979 1486 1957 1611 1975 1275 1973 1057 1971 1970 1969 1968 1815 1966 1965 1964 1963 1013 1961 1960 1959 1958 1977 1956 1955 1954 1953 1952 1113 1950 1949 1948 1657 1946 1945 1944 57 1942 1941...
output:
94089828
result:
ok 1 number(s): "94089828"