QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768386#9748. 最大公因数的平方和0xyzWA 3ms15428kbC++141.4kb2024-11-21 09:57:402024-11-21 09:57:41

Judging History

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

  • [2024-11-21 09:57:41]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:15428kb
  • [2024-11-21 09:57:40]
  • 提交

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);
	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;
}/*
7
2 4 3 1 6 7 5 
7 4 1 5 2 3 6 
1
1 6 6 7

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 15344kb

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:

2
14
12
1
4

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 15428kb

input:

1000
564 82 818 337 917 532 941 590 783 74 256 176 714 159 262 803 869 716 12 448 523 981 664 533 797 520 872 966 710 103 118 101 288 113 363 356 87 475 515 641 147 374 424 788 883 496 230 157 926 942 999 220 886 509 987 99 400 458 993 343 946 684 205 4 925 727 875 939 830 95 486 870 741 846 916 321...

output:

21490984
1224951
277460
5918935
54992262
68717204
1487646
230319251
1696541
874252
822545
69652827
70601586
66778393
3261458
10540347
15664913
85897603
159866555
76151128
52126736
5245980
10101625
222695157
74381244
11352001
47057255
3509727
62148584
29861100
106478852
16350268
31264215
11844295
156...

result:

wrong answer 4th lines differ - expected: '4677079', found: '5918935'