QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142289#10. 卡常数NOI_AK_ME100 ✓501ms20132kbC++234.1kb2023-08-18 21:44:092023-08-18 21:44:12

Judging History

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

  • [2023-08-18 21:44:12]
  • 评测
  • 测评结果:100
  • 用时:501ms
  • 内存:20132kb
  • [2023-08-18 21:44:09]
  • 提交

answer

#include<bits/stdc++.h>
#define abs(a) ((a)<0?-(a):(a))
#define sqr(a) ((a)*(a))
inline int read()
{
	int s=0;
	char c; 
	while((c=getchar())<'0' || c>'9');
	do{s=s*10+c-'0';}while((c=getchar())>='0' && c<='9');
	return s;
}         
inline long double readf()
{
	long double s=0,e=1;
	char c;
	bool f=0;
	while((c=getchar())<'0'||c>'9') if(c=='-') f=1;
	do{s=s*10+c-'0';}while((c=getchar())>='0' && c<='9');
	if(c=='.')
	{
		c=getchar(); 
		do
		{
			s=s+(c-'0')*(e*=0.1);
		}
		while((c=getchar())>='0' && c<='9'); 
	}
	return f?-s:s;                  
}
const int N=68000;
const double eps=1e-9,ea=3;
typedef long long lint;
int n,m,typ[N],et,ans[N];
long double rx[N],ry[N],rz[N],a,b,aa[N],bb[N],cc[N],dd[N];
long double dc(double k)
{
	long double x=(k-b)/a,y=(k+b)/a;
	while(y-x>eps)
	{
		long double mid=(x+y)*0.5;
		if(a*mid-b*sin(mid)<k) 
			x=mid; 
		else 
			y=mid;
	}
	return (long double)x;
}
namespace OSU
{
	lint pr[N],fc[N],ep[N];
	int ps,tot,etot;
	bool np[N];
	void init()
	{
		int i,j;
		np[1]=1;
		for(i=2;i<=n;i++)
		{
			if(!np[i]) 
				pr[++ps]=i;
			for(j=1;j<=ps && pr[j]*i<=n;j++)
			{
				np[pr[j]*i]=1;
				if(i%pr[j]==0) 
					break;
			}
		}
	}
	lint gcd(lint a,lint b)
	{
		while(b)
		{
			a%=b;
			a^=b^=a^=b;
		}
		return a;
	}
	int pollard_osu(lint nn)
	{
		if(nn==1) return 0;
		if(nn<=n && !np[nn]) return 0;
		int i;
		for(i=1;i<=25;i++) if(nn%pr[i]==0) return pr[i];
		int c = 1;
		while(1)
		{
			lint x=1,y=0;
			int tt = 1;
			while(x!=y)
			{
				lint d=gcd((x+nn-y)%nn,nn);
				if(d!=1 && d!=nn) return d;
				if(!(tt&(tt-1))) y = x;
				x = ((unsigned long long)x*x%nn+c)%nn;
				tt++;
			}
			c++;
		}
	}
	void dfs(int nn,lint d)
	{
		if(nn>tot)
		{
			ep[++etot]=d;
			return;
		}
		int l = 0;
		while(l+nn<=tot && fc[nn+l]==fc[nn]) l++;
		for(int i=0;i<=l && d<=n;i++,d*=fc[nn]) dfs(nn+l,d);
	}
	void split(lint nn)
	{
		fc[tot=1]=nn;
		lint d;
		for(int i=1;i<=tot;i++)
		{
			while((d=pollard_osu(fc[i])))
			{
				fc[++tot]=fc[i]/d;
				fc[i]=d;
			}
		}
		std::sort(fc+1,fc+1+tot);
		etot=0;
		dfs(1,1);
	}
}
bool magic(int nn,long double ii)
{
	if(ii<0 || ii>n+1) 
		return 0;
	lint i=(lint)(ii+0.5);
	if(ii-i>1e-5 || i-ii>1e-5) 
		return 0;
	if(i<1 || i>n) 
		return 0;
	if(ans[nn]) 
		return ans[nn]==i;
	long double ea=sqr(rx[i])+sqr(ry[i])+sqr(rz[i]);
	long double eb=-2*(rx[i]*aa[nn]+ry[i]*bb[nn]+rz[i]*cc[nn]);
	long double ec=sqr(aa[nn])+sqr(bb[nn])+sqr(cc[nn])-sqr(dd[nn]);
	long double del=eb*eb-4*ea*ec;
	if(del<0) return 0;
	del=sqrt(del);
	if(magic(nn-1,(-eb+del)/(2*ea)))
	{
		ans[nn]=i;
		return 1;
	}
	if(magic(nn-1,(-eb-del)/(2*ea)))
	{
		ans[nn]=i;
		return 1;
	}
	return 0;
}
int main()
{
	lint i,j;
	n = read(); 
	m = read();
	a = readf(); 
	b = readf();
	for(i=1;i<=n;i++)
	{
		rx[i] = readf();
		ry[i] = readf();
		rz[i] = readf();
	}
	int ls=0,ls2=0;
	for(i=1;i<=m;i++)
	{
		typ[i] = read();
		aa[i] = dc(readf())-1;
		bb[i] = dc(readf())-1;
		cc[i] = dc(readf())-1;
		dd[i] = dc(readf())-1;
	}
	OSU::init();
	bool fst = 1;
	for(int cur=1;cur<=m;cur++)
	{
		if(typ[cur]==0)
		{
			if(fst)
			{
				i = (lint)(aa[cur]*10+0.5);
				rx[i] = bb[cur]*10;
				ry[i] = cc[cur]*10;
				rz[i] = dd[cur]*10;
				ans[cur] = -233;
			}
			else
			{
				i = (lint)(aa[cur]+0.5);
				/*int je=(int)sqrt(i);
				et=0;
				for(j=1;j<=je;j++)
					if(i%j= = 0)
						 e p[++et]=j,ep[++et]=i/j;*/
				OSU::split(i);
				for(j=1;j<=OSU::etot;j++)
				{                          
					lint d1 = OSU::ep[j], d2 = i/d1;
					if(magic(cur-1,d2))
					{
						rx[d1] = bb[cur]/d2;
						ry[d1] = cc[cur]/d2;
						rz[d1] = dd[cur]/d2;
						ans[cur] = d2;
						break;
					}
				}
			}
		}
		else
		{
			if(fst)
			{
				for(i=1;i<=n;i++)
					if(abs(sqr(rx[i]-aa[cur]*10)+sqr(ry[i]-bb[cur]*10)+sqr(rz[i]-cc[cur]*10)-sqr(dd[cur])*100)<1e-5)
					{
						ans[cur] = i;
						break;
					}
				fst = 0;
			}
		}
	}
	for(i=1;i<=n;i++) if(magic(m,i)) break;
	for(i=1;i<=m;i++) if(typ[i]) printf("%d\n",ans[i]);
	return 0;
}

详细

Test #1:

score: 10
Accepted
time: 8ms
memory: 12200kb

input:

1024 1024
3.2 0.1
-5.287133 6.295630 0.635575
3.439587 0.903770 -6.109870
3.659133 -0.479089 -4.140041
3.110743 0.597374 5.087570
3.104021 1.623165 -0.581646
2.345411 -1.247102 -7.224629
-3.519550 5.632687 4.824728
9.729180 -4.808827 4.668826
2.595880 1.924690 -1.475575
6.367650 0.413267 0.327768
-0...

output:

224
829
938
382
109
994
837
925
398
455
272
218
713
28
980
267
213
271
659
154
589
833
260
353
142
9
453
654
22
52
178
463
634
706
767
210
979
918
379
651
918
213
1007
642
548
124
322
156
867
974
5
887
555
559
523
922
227
122
658
916
416
671
424
460
724
526
13
4
592
151
951
493
662
10
950
509
581
93...

result:

ok 537 lines

Test #2:

score: 10
Accepted
time: 11ms
memory: 12092kb

input:

2048 2048
4.6 1.8
-30.324060 92.008512 -10.853952
-48.845284 54.212780 -60.249574
46.753448 -10.585702 66.362382
-11.311727 -94.305948 26.345946
-82.038593 -77.364538 -81.489496
42.342719 90.684519 69.918885
-50.333092 70.160445 15.454933
87.741081 -96.719655 38.652888
97.043464 58.620398 96.784225
...

output:

379
547
694
274
405
1146
862
624
1790
1762
1053
1680
1235
1047
820
155
1157
225
468
1409
1882
1031
564
1518
561
693
1454
186
1573
280
492
160
1392
658
1090
669
84
1160
1397
281
718
1739
2045
714
436
1809
1769
1071
361
1223
1124
949
1814
442
1989
1336
183
1882
354
1427
648
1892
1970
1475
17
1855
1207...

result:

ok 1025 lines

Test #3:

score: 10
Accepted
time: 174ms
memory: 14656kb

input:

32768 32768
4.67 1.56
84.939218 -74.138709 50.938810
-67.042018 68.035250 -70.399291
52.800064 -71.292685 53.225961
-20.525715 33.451823 -65.068592
-25.520097 72.732868 69.097761
22.215709 -57.695300 -48.409886
35.446509 90.710192 -35.680885
-60.561016 -60.517046 -8.174342
-77.935361 -78.840195 95.3...

output:

30194
13684
10956
15758
174
19007
18158
23240
25026
17904
16643
30463
27249
3243
3546
10499
3366
7676
3122
1332
8214
2722
13901
4062
3706
15245
21820
18895
12238
31657
18242
28323
31341
3717
4207
15633
15292
23865
22362
29184
28802
29920
331
15141
28229
22957
12750
7559
20583
28938
28647
31100
12514...

result:

ok 32768 lines

Test #4:

score: 10
Accepted
time: 305ms
memory: 18428kb

input:

32768 65536
3.95 0.18
14.056154 -30.150315 -77.588418
-98.232666 83.048322 36.852302
-16.963898 46.003829 -7.166507
-89.241244 -52.920748 -2.452281
-4.172825 -65.045528 -31.485175
-37.297909 50.213395 -21.809664
37.396983 34.533676 -29.251241
6.265591 78.434812 -14.170830
-86.676235 57.457258 -27.81...

output:

6818
11667
18789
19903
24629
26273
31179
23551
2792
6648
19713
7397
25796
11804
30273
26138
9184
24388
25836
13145
21833
31986
23407
6032
9558
1821
1439
27617
31451
27473
22124
26465
9438
12231
9406
24454
28202
17980
30341
2117
25526
23953
17065
9751
16346
23470
32478
2890
2603
4387
25200
29686
2350...

result:

ok 65536 lines

Test #5:

score: 10
Accepted
time: 358ms
memory: 20132kb

input:

65536 65536
3.06 1.68
34.778462 22.247101 40.136088
22.245748 -43.219166 36.823722
65.928250 18.907994 -63.575439
95.838739 -77.231227 -1.609640
91.379763 4.112603 34.286943
-89.447280 2.078495 -46.947085
64.595702 -0.000307 -30.701957
78.546814 88.734645 -22.303236
26.093877 18.363883 -49.280232
-5...

output:

965
51532
14313
17256
36766
32794
36123
53973
43046
60200
16961
42820
18796
62531
59798
5846
63060
22453
50159
14557
39189
60480
12535
6080
41671
56075
38213
61477
25789
35310
21010
803
31397
13805
10669
43897
29456
8853
33549
23293
24557
56189
44711
285
5284
62335
8447
57794
10496
36434
34375
63444...

result:

ok 65536 lines

Test #6:

score: 10
Accepted
time: 246ms
memory: 11208kb

input:

32768 32768
4.25 3.98
16.261407 -3.579866 -79.159513
67.679089 -65.363455 78.768393
-36.872553 -27.651661 -15.273458
-20.905831 -25.161722 51.595933
-28.875568 -13.795375 39.138869
-19.301905 -29.707336 -57.471115
-53.548147 -33.829020 6.242839
26.216947 17.319888 -52.002265
-52.486606 -15.583705 -1...

output:

24478
11026
4116
29512
9951
27007
31104
16697
272
25060
14354
361
2835
10248
2196
11761
25261
19457
12412
29583
10162
2313
11956
31356
12666
14007
30646
17391
20034
27171
21355
18273
4381
17294
25741
21905
6812
12608
6624
2947
29946
15588
26467
12293
29728
15095
29175
23703
12023
9469
29626
20775
24...

result:

ok 16486 lines

Test #7:

score: 10
Accepted
time: 475ms
memory: 12796kb

input:

32768 65536
2.28 2.08
-77.539108 9.020113 90.951933
-40.160423 -96.331979 80.089815
13.993026 -93.826031 -29.018021
92.664856 -33.089080 -0.657607
27.876505 22.826064 62.292361
-47.323183 -13.426563 -16.066616
81.711794 24.884818 -80.739379
18.337828 73.486039 71.076694
-98.992748 -17.695182 10.0227...

output:

8314
817
29663
22078
32598
14726
20716
4292
18454
25135
21244
15906
1350
3194
57
17179
7910
14960
18779
14505
19930
27810
22363
18653
3220
2562
11412
30399
8745
28613
31874
3893
30115
15461
27076
17864
23222
24525
23744
16663
30531
11444
8154
4925
8181
8888
539
1128
25039
20380
28158
31678
1544
2833...

result:

ok 32729 lines

Test #8:

score: 10
Accepted
time: 254ms
memory: 12548kb

input:

65536 32768
0.59 0.24
99.020814 -8.178256 99.557830
82.020375 18.019102 96.790487
48.083018 -78.152933 -19.288388
31.203678 95.123958 -66.973623
-83.940507 75.473022 -29.148823
4.254775 -90.825004 38.106763
64.658227 16.176496 -3.497318
-86.506375 -48.219119 -62.340429
64.209428 -40.757806 57.081505...

output:

28055
17574
59341
18595
11741
40334
52974
36632
30320
43060
27780
38454
1454
12749
60789
43230
55763
27464
16696
29394
37841
1878
62068
39368
4733
43278
42938
31784
52264
393
31980
39596
47733
18410
23169
31471
10041
33772
42838
20863
64543
2338
37677
1830
14709
40569
13229
40316
25381
36861
53405
5...

result:

ok 16469 lines

Test #9:

score: 10
Accepted
time: 501ms
memory: 13340kb

input:

65536 65536
3.73 2.51
94.030160 -12.854842 -79.582087
99.708537 41.749589 -15.411580
-83.599242 -68.178210 9.579776
27.223008 66.351912 32.660029
-26.067712 -25.960860 -26.511404
71.015179 70.420405 -75.586624
58.776519 -10.874757 -42.559339
69.191366 -18.690434 41.428921
33.289206 92.676136 22.0591...

output:

32043
44897
5234
48758
38485
45399
17831
29941
20873
51166
21736
51634
56064
47866
32900
60637
44556
51267
64529
37570
63436
8100
47139
1824
33989
26745
39094
30066
10251
14021
19773
9816
10352
25219
7128
50887
30132
5362
46508
60651
57733
42918
7282
33355
31935
24715
39443
65293
32586
27809
27109
3...

result:

ok 32727 lines

Test #10:

score: 10
Accepted
time: 472ms
memory: 12144kb

input:

65536 65536
2.54 0.67
78.221262 -73.957753 14.147439
39.328747 -22.396923 -70.131354
56.912390 70.724316 -30.562216
-12.046663 -10.503612 99.157809
-59.432409 28.684196 26.256164
13.311709 -35.565339 7.841181
60.081195 42.648279 33.916067
94.845938 -45.203322 -12.839457
10.129303 -43.764821 -2.62406...

output:

43349
2492
12336
11664
63943
27564
7922
57385
4573
4123
45077
44601
25768
52876
44596
47364
44386
58511
10547
20422
18092
10086
54785
53842
51182
54646
23966
14542
25838
16309
34735
57175
8204
13372
24640
5297
10871
48981
42948
46069
38459
22992
37418
15280
61928
28802
45321
14698
7522
49751
46454
4...

result:

ok 32844 lines