QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767537#9748. 最大公因数的平方和wtcWA 29ms15484kbC++141.3kb2024-11-20 21:12:492024-11-20 21:12:49

Judging History

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

  • [2024-11-20 21:12:49]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:15484kb
  • [2024-11-20 21:12:49]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define ll long long
#define int ll
using namespace std;
const int N=100007,B=1000;
int n,Q,a[N],b[N],c[N],d[N],sum[N],bz[N];
ll f[N],g[N],ans[N];
vector<int>p[N];
struct Qry{
	int l,r,bh,c;
};
vector<Qry>q[N];
void upd(int x,ll y){while(x<=n)g[x]+=y,x+=x&-x;}
ll qry(int x){ll s=0;while(x)s+=g[x],x-=x&-x;return s;}
void init(int n)
{
	fo(i,1,n) f[i]=1ll*i*i;
	fo(i,2,n)
		if(!bz[i])
		{
			for(int j=n/i*i;j>=i;j-=i) f[j]-=f[j/i],bz[j]=1;
		}
}
signed main()
{
	scanf("%lld",&n);
	init(n);
	fo(i,1,n) scanf("%lld",&a[i]),c[a[i]]=i;
	fo(i,1,n) scanf("%lld",&b[i]),d[b[i]]=i;
	fo(i,B+1,n)
	{
		for(int j=i;j<=n;j+=i)
			p[c[j]].push_back(i);
	}
	scanf("%lld",&Q);
	fo(i,1,Q)
	{
		int l,r,u,v;
		scanf("%lld%lld%lld%lld",&l,&r,&u,&v);
		q[r].push_back((Qry){u,v,i,1});
		q[l-1].push_back((Qry){u,v,i,-1});
	}
	fo(j,1,B)
	{
		fo(i,1,n) sum[i]=sum[i-1]+(b[i]%j==0);
		int w=0;
		fo(i,1,n)
		{
			w+=(a[i]%j==0);
			for(Qry x:q[i]) ans[x.bh]+=1ll*(sum[x.r]-sum[x.l-1])*w*f[j]*x.c;
		}
	}
	fo(i,1,n)
	{
		for(int x:p[i])
		{
			for(int y=x;y<=n;y+=x) upd(d[y],f[x]);
		}
		for(Qry x:q[i]) ans[x.bh]+=(qry(x.r)-qry(x.l-1))*x.c;
	}
	fo(i,1,Q) printf("%lld\n",ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 4ms
memory: 13620kb

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
4677079
45620670
68717204
1487646
213162875
1696541
874252
822545
69652827
56058810
47821969
3261458
10540347
15664913
80605699
139540643
76151128
52126736
5245980
10101625
152049237
55449324
11352001
47057255
3509727
62148584
29861100
106478852
16350268
31181559
8679031
1564...

result:

ok 100 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 15448kb

input:

1000
840 720 960 900 936 660 756 924 360 780 864 480 540 504 420 630 600 990 672 792 576 336 810 528 912 240 816 648 880 432 560 624 828 288 588 300 700 252 612 768 800 882 684 468 980 450 180 396 972 552 702 510 168 546 888 594 896 930 312 870 1000 680 280 210 270 216 858 570 910 264 696 920 520 69...

output:

6552686
533067
169126
49
94392
15874
646003
9382
45717
1
456976
1
1
91544660
261221
4
1
73636
136002694
11087
467
697765
878
35
1
170897
96
221941
8716057
702144
623544
108101127
453642
289514
953537
14504512
11427616
146345360
16
688131
1
809601
343338
4
1
664608
1
2864172
1116528
1
304730035
47964...

result:

ok 100 lines

Test #4:

score: -100
Wrong Answer
time: 29ms
memory: 12928kb

input:

5000
812 2241 3168 254 2304 2907 711 1116 2083 3445 755 4289 1848 2265 1481 4458 1701 4233 3301 4425 3793 1937 4891 4422 3891 556 2867 4041 1020 4089 3388 1013 729 896 870 365 1621 3506 2575 2714 4405 2449 326 3935 3480 4801 166 4269 1256 1587 4240 1503 3768 868 3997 1730 1077 2061 2353 2224 4528 27...

output:

807941321
455240624
6922504916
19604004336
6883982707
16476036202
2113263772
1298284545
11996631762
10665960907
12803742566
5263081555
3793172020
1976412878
2776780447
5633359078
6675816514
25100338813
1067059142
9004556591
107082133
600207777
621583381
8171008454
4428820689
13601963817
27174028003
...

result:

wrong answer 3rd lines differ - expected: '2627537620', found: '6922504916'