QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#85748 | #1060. 快速查询 | lmeowdn | 0 | 947ms | 124808kb | C++14 | 2.5kb | 2023-03-08 10:53:42 | 2023-03-08 10:53:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
#define sgn(x) ((x)&1?-1:1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
return x*w;
}
const int N=1e5+9,mod=1e7+19;
int n,m,op[N],X[N],V[N],A[N],B[N],tmp[N],cnt,T,a[N],t[N],x,y,z,w,sum,tsum;
signed fac[mod+5],ifac[mod+5],inv[mod+5];
int ksm(int x,int y,int r=1) {
for(;y;y>>=1,x=x*x%mod) if(y%2==1) r=r*x%mod;
return r;
}
void pre() {
fac[0]=1, ifac[0]=1, fac[0]=1;
rep(i,1,mod-1) fac[i]=1ll*fac[i-1]*i%mod;
ifac[mod-1]=ksm(fac[mod-1],mod-2);
per(i,mod-2,1) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
rep(i,1,mod-1) inv[i]=1ll*ifac[i]*fac[i-1]%mod;
rep(i,1,mod-1) assert(inv[i]==ksm(i,mod-2));
}
int getval(int i) {
if(t[i]>w) return (x*a[i]+y)%mod;
else return (x*z+y)%mod;
}
void mdf(int i,int v,int d) {
sum-=getval(i), t[i]=d, a[i]=(v-y+mod)*inv[x]%mod, sum+=getval(i);
sum=(sum%mod+mod)%mod;
}
void add(int v) {y=(y+v)%mod, sum=(sum+v*n)%mod;}
void mul(int v) {x=x*v%mod, y=y*v%mod, sum=(sum*v)%mod;}
void cov(int v,int d) {w=d, x=1, y=0, z=v, sum=n*v%mod;}
signed main() {
pre();
n=read(), m=read();
rep(i,1,m) {
op[i]=read();
if(op[i]==1) X[i]=read(), V[i]=read()%mod, tmp[++cnt]=X[i];
else if(op[i]==2) V[i]=read()%mod;
else if(op[i]==3) V[i]=read()%mod;
else if(op[i]==4) V[i]=read()%mod;
else if(op[i]==5) X[i]=read()%mod, tmp[++cnt]=X[i];
}
rep(i,1,m) if(V[i]<0) V[i]+=mod;
T=read();
rep(i,1,T) A[i]=read(), B[i]=read();
sort(tmp+1,tmp+cnt+1); cnt=unique(tmp+1,tmp+cnt+1)-tmp-1;
rep(i,1,m) if(X[i]) X[i]=lower_bound(tmp+1,tmp+cnt+1,X[i])-tmp;
x=1, y=0, z=0;
rep(i,1,T) rep(j,1,m) {
int id=(A[i]+j*B[i])%m+1, d=(i-1)*m+j;
if(op[id]==1) mdf(X[id],V[id],d);
else if(op[id]==2) add(V[id]);
else if(op[id]==3) mul(V[id]);
else if(op[id]==4) cov(V[id],d);
else if(op[id]==5) tsum=(tsum+getval(X[id]))%mod;
else if(op[id]==6) tsum=(tsum+sum)%mod;
}
printf("%lld\n",tsum);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 947ms
memory: 124808kb
input:
452026 95958 1 285703 217433997 1 11660 355946119 1 154677 958212086 1 45777 559001183 1 149425 708949937 1 199039 -627813211 1 421465 878181683 1 18566 -840518154 1 268546 -956473636 1 6627 -168874651 1 165349 796846652 1 389787 -241387034 2 856579071 2 776291767 1 361873 220652502 1 34945 3586417 ...
output:
2938818
result:
wrong answer 1st lines differ - expected: '7032812', found: '2938818'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%