显然
f
w
t
fwt
fwt数组内只有
l
o
g
log
log个不同的值
且可以直接用
O
(
位
数
)
O(位数)
O(位数)个数表示
而稍微考虑一下会发现两个数组异或卷积后仍然满足这个性质
具体可以考虑按照位数从大到小归纳证明
顺带可以推出数列异或卷积后的样子
然后就可以
O
(
n
l
o
g
n
)
O(nlogn)
O(nlogn)做完了
注意除了每一位对应一个后还剩下一个点没有表示,要单独记一下
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int mod=998244353;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}
cs int M=21,N=1000005;
int n,m,q;
struct data{
bool vp[M];
int val[M],els;
inline void init(int x,int v){
for(int i=19,I;~i;i--)if(x&(1<<i)){
vp[i]=1,I=x-(x&((1<<i)-1)),val[i]=mul(I,I^v);
}else vp[i]=0;
}
friend inline data operator *(cs data &a,cs data &b){
data c;
int sa=a.els,sb=b.els;
for(int i=19;~i;i--)
Add(sa,mul(a.val[i],1<<i)),Add(sb,mul(b.val[i],1<<i));
int s=0;
for(int i=19;~i;i--){
Dec(sa,mul(a.val[i],1<<i)),Dec(sb,mul(b.val[i],1<<i));
c.vp[i]=a.vp[i]^b.vp[i];
c.val[i]=add(s,add(mul(a.val[i],sb),mul(b.val[i],sa)));
Add(s,mul(mul(a.val[i],b.val[i]),1<<i));
}
c.els=add(s,mul(a.els,b.els));
return c;
}
inline int query(int p){
for(int i=19;~i;i--)if((((p>>i)&1)^1^vp[i])==0){return val[i];}
return els;
}
}f[N];
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read(),m=read(),q=read();
for(int i=1;i<=n;i++){
int x=read(),v=read();
f[i].init(x,v);
}
for(int i=2;i<=n;i++)f[i]=f[i-1]*f[i];
while(q--){
int c=read(),d=read();
cout<<f[c].query(d)<<'\n';
}
}