QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414874 | #8717. 骰子 | bulijiojiodibuliduo# | WA | 1533ms | 46896kb | C++17 | 3.3kb | 2024-05-19 23:17:20 | 2024-05-19 23:17:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=mod*mod;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
typedef unsigned long long ull;
const int Q=601000,N=1510,M=210;
ull p[N][M],pl[N][M],pr[N][M],Pl[N][M],Pr[N][M],pw[N][M];
ll f[N],g[N],cc[N],b[N],fac[N],ans[Q];
int n,m,q;
void mul(ull *a,ull *b,ull *c) {
rep(i,0,m+1) {
a[i]=0;
for (int j=0;j<=i;j++) {
a[i]+=b[j]*c[i-j];
if (a[i]>=mod2) a[i]-=mod2;
}
a[i]%=mod;
}
}
void eval(ull *a,ull *b) {
rep(i,0,2*m+1) {
//a[i]=0;
unsigned long long x=0;
ull *c=pw[i];
int j=0;
for (;j+16<=m;j+=16) {
x+=b[j+0]*c[j+0]+b[j+1]*c[j+1]+b[j+2]*c[j+2]+b[j+3]*c[j+3]+
b[j+4]*c[j+4]+b[j+5]*c[j+5]+b[j+6]*c[j+6]+b[j+7]*c[j+7]+
b[j+8]*c[j+8]+b[j+9]*c[j+9]+b[j+10]*c[j+10]+b[j+11]*c[j+11]+
b[j+12]*c[j+12]+b[j+13]*c[j+13]+b[j+14]*c[j+14]+b[j+15]*c[j+15];
x%=mod;
}
for (;j<=m;j++) {
x+=b[j]*c[j];
}
a[i]=x%mod;
}
/*rep(i,0,m+1) printf("%lld ",b[i]); puts("eval");
rep(i,0,2*m+1) printf("%lld ",a[i]); puts("");*/
}
void solve(int l,int r,vector<array<int,3>> &ret) {
if (ret.empty()) return;
int md=(l+r)>>1;
vector<array<int,3>> L,R,M;
for (auto c:ret) {
if (c[1]<md) L.pb(c);
else if (c[0]>md+1) R.pb(c);
else M.pb(c);
}
if (l<=md-1) solve(l,md-1,L);
if (md+2<=r) solve(md+2,r,R);
rep(i,0,m+1) {
pr[md][i]=(i==0)?1:0;
pl[md+1][i]=(i==0)?1:0;
}
rep(pos,md+1,r+1) mul(pr[pos],pr[pos-1],p[pos]);
per(pos,l,md+1) mul(pl[pos],pl[pos+1],p[pos]);
rep(pos,md,r+1) eval(Pr[pos],pr[pos]);
per(pos,l,md+2) eval(Pl[pos],pl[pos]);
for (auto [vl,vr,id]:M) {
ll z=0;
//printf("-- %d %d %d %d\n",vl,vr,l,r);
rep(i,0,2*m+1) {
//printf("%lld ",Pl[vl][i]*Pr[vr][i]%mod);
z=(z+Pl[vl][i]*Pr[vr][i]%mod*cc[i])%mod;
}
//puts("");
ans[id]=z;
}
}
int main() {
scanf("%d%d%d",&n,&m,&q);
rep(i,0,m+1) {
scanf("%lld",&b[i]);
}
rep(i,0,2*m+1) {
pw[i][0]=1;
rep(j,1,m+1) pw[i][j]=pw[i][j-1]*i%mod;
}
rep(i,1,n+1) rep(j,0,m+1) {
scanf("%lld",&p[i][j]);
p[i][j]%=mod;
}
int v=2*m+1;
g[0]=1;
rep(i,0,v) {
per(j,0,i+1) {
g[j+1]=(g[j+1]+g[j])%mod;
g[j]=(ll)g[j]*(mod-i)%mod;
}
}
fac[0]=1;
rep(i,1,v+1) fac[i]=(ll)fac[i-1]*i%mod;
rep(i,0,v) {
rep(j,0,v+1) f[j]=g[j];
per(j,1,v+1) {
f[j-1]=(f[j-1]+(ll)f[j]*i)%mod;
}
ll coef=(ll)fac[i]*fac[v-1-i]%mod*powmod(mod-1,v-1-i)%mod;
coef=powmod(coef,mod-2);
rep(j,0,v) cc[i]=(cc[i]+coef*f[j+1]%mod*b[j])%mod;
}
//rep(i,0,v) printf("!! %lld\n",cc[i]);
vector<array<int,3>> ret;
rep(i,0,q) {
int l,r;
scanf("%d%d",&l,&r);
//l=rnd(n)+1,r=rnd(n)+1;
if (l>r) swap(l,r);
ret.pb({l,r,i});
}
solve(1,n,ret);
rep(i,0,q) printf("%lld\n",ans[i]);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 16068kb
input:
3 3 3 4 3 2 1 0 1 0 1000000007 0 500000004 0 500000004 0 0 500000004 500000004 1 1 1 2 1 3
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: 0
Accepted
time: 2ms
memory: 16352kb
input:
3 3 6 4 3 2 1 1000000007 0 1 0 1000000007 1 0 0 1000000007 0 1 0 1 1 1 2 1 3 2 2 2 3 3 3
output:
2 1 0 3 1 2
result:
ok 6 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 16164kb
input:
1 1 1 604063100 57375033 742299910 257700098 1 1
output:
148903503
result:
ok 1 number(s): "148903503"
Test #4:
score: -100
Wrong Answer
time: 1533ms
memory: 46896kb
input:
1500 200 600000 253665324 876103781 804024983 929290295 908790466 176299158 528078340 696679927 416465140 509641654 705083449 361711737 250659645 735832780 35321360 383752049 203979021 178832532 785212637 514502839 169840231 65809146 504755349 516829442 382478309 901925498 142312128 782336477 741339...
output:
224464837 984811683 507099119 690048028 575911078 867188136 571704655 278059355 10360712 171289464 891434256 6774266 399024050 755920469 475106541 298533462 88592716 13485718 740102543 584615082 967166505 808466122 688638132 552229476 80387133 348544554 854163047 229794769 280615077 980040557 353032...
result:
wrong answer 1st numbers differ - expected: '66394849', found: '224464837'