QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768421#9748. 最大公因数的平方和0xyzWA 4ms11348kbC++141.2kb2024-11-21 10:22:362024-11-21 10:22:36

Judging History

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

  • [2024-11-21 10:22:36]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:11348kb
  • [2024-11-21 10:22:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned int ll;
const ll _=1e5+5,B=5,C=5;
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 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]-C+1;i<=r;i++)w+=u[i];
	}
	return w;
}
int main(){
	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 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,4294967295}),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)u[d[k]]+=f[j],v[c[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;
}

详细

Test #1:

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

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: 4ms
memory: 10680kb

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:

21461282
1222696
277241
4675014
45574442
68690791
1486554
213058176
1692634
873286
822543
69625674
56026430
47790918
3259704
10532927
15649260
80564521
139452776
76089133
52091130
5240902
10073223
151940029
55391169
11345400
47026918
3508933
62125125
29848546
106427603
16333920
31168369
8670013
1563...

result:

wrong answer 1st lines differ - expected: '21490984', found: '21461282'