QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768383#9748. 最大公因数的平方和0xyzRE 0ms0kbC++141.4kb2024-11-21 09:56:422024-11-21 09:56:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 09:56:43]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-21 09:56:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll _=1e5+5,B=320,C=320;
struct qr{ll w,x,y,z;};
vector<qr>q[_];
vector<ll>g[_];
ll u[_],v[_],d[_],a[_],b[_],c[_],f[_],s[_],t[_],w[_],o[_],n,m;
inline void add(ll p,ll k){
	u[p]+=k;v[c[p]]+=k;
}
inline ll sum(ll l,ll r){
	ll w=0;
	if(l+C>=r){
		for(ll i=l;i<=r;i++)w+=u[i];
	}else{
		for(ll i=l;i<=C*c[l];i++)w+=u[i];
		for(ll i=c[l]+1;i<=c[r];i++)w+=v[i];
		for(ll i=C*c[r]+1;i<=r;i++)w+=u[i];
	}
	return w;
}
int main(){
	freopen("qwq.in","r",stdin);
	freopen("qwq.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(ll i=1;i<=n;i++)cin>>a[i],c[i]=(i-1)/C+1;
	for(ll i=1;i<=n;i++)cin>>b[i],d[b[i]]=i;
	o[1]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=2;j*i<=n;j++)o[i*j]-=o[i];
	for(ll i=1;i<=n;i++)
		for(ll j=1;j*i<=n;j++)f[i*j]+=i*i*o[j],g[i*j].push_back(i);
	for(ll i=1;i<=n;i++)cout<<f[i]<<'\n';
	cin>>m;
	for(ll i=1,x,y,X,Y;i<=m;i++){
		cin>>x>>y>>X>>Y;
		q[x-1].push_back({X,Y,i,-1});
		q[y].push_back({X,Y,i,1});
	}
	for(ll i=1;i<=B;i++){
		for(ll j=1;j<=n;j++)s[j]=s[j-1]+(a[j]%i==0),t[j]=t[j-1]+(b[j]%i==0);
		for(ll j=1;j<=n;j++)
			for(qr k:q[j])w[k.y]+=k.z*f[i]*s[j]*(t[k.x]-t[k.w-1]);
	}
	for(ll i=1;i<=n;i++){
		for(ll j:g[a[i]])
			if(j>B)
				for(ll k=j;k<=n;k+=j)add(d[k],f[j]);
		for(qr j:q[i])w[j.y]+=j.z*sum(j.w,j.x);
	}
	for(ll i=1;i<=m;i++)cout<<w[i]<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

5
4 1 5 3 2
1 2 3 4 5
5
3 3 2 3
3 4 2 4
3 4 3 4
5 5 1 1
1 1 2 2

output:


result: