QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189404 | #7237. Sort it! | haze | WA | 25ms | 24780kb | C++23 | 2.0kb | 2023-09-27 14:19:47 | 2023-09-27 14:19:48 |
Judging History
answer
#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
const int itinf = 2e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 2007;
int p[N], ord[N];
ll f[N], g[N][N], fr[N] = {1};
struct BIT{
int n;
vector<ll>t;
BIT(){}
BIT(int nn){
n = nn;
t.resize(n + 1);
}
void insert(int x,int val){
for(;x <= n; x += (x & -x)){
t[x] = (t[x] + val) % mod;
}
}
ll query(int x){
ll ans = 0;
for(; x; x -= (x & -x))ans += t[x], t[x] %= mod;
return ans;
}
ll ask(int x){
return query(x) - query(x - 1);
}
void clear(){
irep(i,0,n)t[i] = 0;
}
};
BIT t[N];
ll qpow(ll base, ll b){
ll ans = 1;
while(b){
if(b & 1)ans *= base, ans %= mod;
base *= base, base %= mod, b >>= 1;
}
return ans;
}
int main(){
int n = read();
ll ans = 0;
for(int i = 1; i <= n; ++i){
p[i] = read();
ord[p[i]] = i;
t[i].t.resize(n + 1);
t[i].n = n;
fr[i] = 1ll * fr[i - 1] * i % mod;
}
for(int j = 1; j <= n; ++ j){
int x = ord[j];
for(int i = 1; i <= n; ++ i){
if(i == 1)t[i].insert(x, 1);
else t[i].insert(x, t[i - 1].query(x - 1));
}
}
for(int i = 1; i <= n; ++i)f[i] = t[i].query(n);
g[0][0] = 1;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= i; ++ j){
g[i][j] = g[i - 1][j] * j + g[i - 1][j - 1];
g[i][j] %= mod;
}
}
for(int i = 1; i <= n; ++ i){
ans += fr[i] * g[n][i] % mod * f[i] % mod;
}
printf("%lld",ans % mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5696kb
input:
2 2 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 2 1 3
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
2 1 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
3 1 2 3
output:
27
result:
ok 1 number(s): "27"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 1 3 2
output:
15
result:
ok 1 number(s): "15"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
3 2 3 1
output:
9
result:
ok 1 number(s): "9"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
3 3 1 2
output:
9
result:
ok 1 number(s): "9"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3920kb
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: 3772kb
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: -100
Wrong Answer
time: 25ms
memory: 24780kb
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:
739498521
result:
wrong answer 1st numbers differ - expected: '333399230', found: '739498521'