QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768331#9748. 最大公因数的平方和0xyzWA 4ms15696kbC++141.4kb2024-11-21 09:24:442024-11-21 09:24:54

Judging History

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

  • [2024-11-21 09:24:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:15696kb
  • [2024-11-21 09:24:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll _=1e5+5,B=320,C=320;
struct qr{ll 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(int i=l;i<=r;i++)w+=u[i];
	}else{
		for(int i=l;i<=C*c[l];i++)w+=u[i];
		for(int i=c[l]+1;i<=c[r];i++)w+=v[i];
		for(int i=C*c[r]+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 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-1,i,1});
		q[x-1].push_back({Y,i,-1});
		q[y].push_back({X-1,i,-1});
		q[y].push_back({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];
	}
	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(1,j.x);
	}
	for(ll i=1;i<=m;i++)cout<<w[i]<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 15216kb

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: 15696kb

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:

44258080
1224951
277460
5918935
54992262
18694868
635286
194274803
1696541
1756564
16145
17041515
70601586
51623665
1192970
4891347
35629769
85897603
159866555
100218760
24904760
2323716
10101625
222695157
74381244
5534089
109555583
2854239
16099832
8031084
171841364
35068396
31264215
11844295
59948...

result:

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