QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#940137#9035. GOSICKL_Hospital_AC ✓2213ms83040kbC++141.7kb2025-03-17 17:41:342025-03-17 17:41:36

Judging History

This is the latest submission verdict.

  • [2025-03-17 17:41:36]
  • Judged
  • Verdict: AC
  • Time: 2213ms
  • Memory: 83040kb
  • [2025-03-17 17:41:34]
  • Submitted

answer

#include<bits/stdc++.h>
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define N 500005
# define B 1201
using namespace std;

int fac[N], now[N], x[7000005];
basic_string < int > plc[N], big[1005];
int p[41540], cnt, len[41540];
int n, m, a[N];
int l[N], r[N], xl[N], xr[N], b[N], bl[1005], br[1005], d[N], xd[N];
long long pre[N], ans[N];
signed main()
{
	ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	cin >> n >> m;
	rep(i, 1, 500000) for (int j = i; j <= 500000; j += i) ++fac[j];
	rep(i, 1, 500000) if (fac[i] == 2) p[++cnt] = i, len[cnt] = 500000 / i;
	rep(i, 1, 500000) fac[i] += fac[i - 1], now[i] = fac[i - 1] + 1;
	rep(i, 1, 500000) for (int j = i; j <= 500000; j += i) x[now[j]++] = i;
	rep(i, 1, 1000) bl[i] = 500000;
	rep(i, 1, n) b[i] = (i + 700) / B, bl[b[i]] = min(bl[b[i]], i), br[b[i]] = max(br[b[i]], i);
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, m) cin >> l[i] >> r[i], plc[l[i] - 1].push_back(i), plc[r[i]].push_back(i);
	rep(i, 1, m) if (b[l[i]] < b[r[i]] - 1) big[b[l[i]]].push_back(i), big[b[r[i]] - 1].push_back(i);
	rep(i, 1, n)
	{
		rep(j, fac[a[i] - 1] + 1, fac[a[i]]) ++d[x[j]];
		for (auto j : plc[i])
		{
			int now = 0;
			if (b[l[j]] == b[r[j]]) rep(i, l[j], r[j]) now += d[a[i]];
			else {rep(k, l[j], br[b[l[j]]]) now += d[a[k]]; rep(k, bl[b[r[j]]], r[j]) now += d[a[k]];}
			ans[j] += (i == r[j] ? now : -now);
		}
	}
	rep(i, 0, b[n])
	{
	    rep(j, bl[i], br[i]) ++xd[a[j]];
	    rep(i, 1, 500000) d[i] = xd[i];
		rep(j, 1, cnt) rep(k, 1, len[j]) d[k * p[j]] += d[k];
		rep(j, 1, n) pre[j] = pre[j - 1] + d[a[j]];
		for (auto j : big[i]) ans[j] += (b[l[j]] == i ? -1 : 1) * (pre[r[j]] - pre[l[j] - 1]);
	}
	rep(i, 1, m) cout << ans[i] << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1890ms
memory: 80972kb

input:

500000 500000
88 456144 460512 374640 291648 401280 244296 228096 660 365904 163680 66240 344448 6 460460 220 25200 182160 476112 321024 178920 323232 245952 335016 256500 122304 30450 216000 440 423280 540 588 199056 155610 184140 36 382536 450240 365148 34 299460 230400 154560 394240 120 326400 26...

output:

578504328
856408172
2848798553
6063856259
2175171949
138271099
1604102587
3353183485
2018830373
1465346157
320445977
640568008
10080012888
9953475098
948818389
176737772
4640966737
3701928490
352905152
2970282143
1052929431
1641773603
6313451447
1158672989
2500925323
277726346
11765392502
2688402764...

result:

ok 500000 lines

Test #2:

score: 0
Accepted
time: 1843ms
memory: 80928kb

input:

500000 500000
183456 567 364320 280 912 1360 253890 819 2145 480816 271040 293328 245 10 328944 352560 20160 68 198900 471240 381840 290700 300 473200 439110 466560 4 18 105 288 418950 72 183540 2870 165312 96 96 390 48 66528 28560 5936 77 8 382536 96 371448 952 494760 187920 558 275880 2220 360 492...

output:

759702430
6397322745
7640760531
7644131391
9226557876
260624499
675735537
5181410739
4931194169
549901793
15363448165
725538899
148833830
324526291
2353707827
2747734440
3370954619
725829950
23702699
1072500217
2900537183
20084831
15704366114
9211406034
1727888601
4796089488
1034342915
3866749960
68...

result:

ok 500000 lines

Test #3:

score: 0
Accepted
time: 1804ms
memory: 80980kb

input:

500000 500000
285 704 1470 328860 422240 7 2250 255 70 3960 39 180 4860 9 400200 570 330240 990 80 44 105840 91 3996 72 232470 1880 215424 334530 3 288144 176400 18 1950 246400 315360 215424 275 302328 72 29 7920 205128 1092 3 78 44 442890 308 1092 330372 442000 1 400 96 4200 217140 78 5 810 58 585 ...

output:

1184051312
149659451
11556080584
1480429688
1343461257
2224661717
14983201991
960649079
226138089
9043777049
169672721
754882799
20055238308
3164059055
14373783353
2539933738
1958868034
23332218529
676834620
710115615
3768567548
3724346223
175932129
4090453435
1611252408
4935301387
4908261757
123281...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 1791ms
memory: 81060kb

input:

500000 500000
49 240408 7140 80 268 342 13 3 30 450 3432 2640 4 209 3240 60 39 39 81600 90 14310 20 4 156 1140 2562 1260 323232 427728 3 28 10 720 384750 1512 66 80 440 487760 44 314280 420336 80 819 3248 43680 5265 74 11 296 1248 70 31680 17 1 900 612 378480 60 39 1400 1755 470610 660 10440 3120 11...

output:

4156231445
2510215757
2264967157
5431050269
3809312033
805959443
577512359
3042491193
315518983
8115400526
12284492
10502255798
3614363679
106307737
6979883800
17555714502
1731873855
3777891081
2843100625
462420332
4342961
2355533358
4410572241
4582004
3611804388
6725366245
1113429391
46046743
14456...

result:

ok 500000 lines

Test #5:

score: 0
Accepted
time: 1979ms
memory: 80868kb

input:

500000 500000
266400 350550 16 298452 1 248472 90 290700 326430 273840 373968 255024 330750 455112 299200 324324 417300 340380 457470 384120 81648 168 434112 175770 401184 397488 5 246330 239700 62832 780 408576 227556 1725 449460 52800 214320 72576 226560 381216 414000 304416 156960 179280 109368 1...

output:

3679315163
547361238
2189558828
1568275168
1128894163
6472808589
852742819
64059667
3586025516
5491261560
57918400
40849373
1663202357
2355857743
169464887
1441121716
44749508
2668019527
2669709761
5897366
916164798
5207867990
1017729032
1350898
1595284780
813821443
312062175
52133562
2121523147
142...

result:

ok 500000 lines

Test #6:

score: 0
Accepted
time: 1949ms
memory: 81016kb

input:

500000 500000
461538 362880 16 141900 119520 3360 362304 66780 69120 261800 6300 4 192660 476700 4 257280 193116 322080 120120 307008 137340 104160 36 428652 3290 1078 22 319788 278124 271950 44640 177120 262656 404976 472140 59040 422100 1323 320760 21 228000 469700 1395 404712 191520 185724 54000 ...

output:

523894615
439082871
12049725440
67535623
2104798292
69391256
340138481
139437365
4864194733
8081196967
16459199653
1067269470
442352903
883178903
4308945816
2836450585
1919616478
3175196078
2153724957
1312866369
389584910
3902983976
357797918
1080637824
710360166
124168106
2046268
41080424
344627630...

result:

ok 500000 lines

Test #7:

score: 0
Accepted
time: 1890ms
memory: 80940kb

input:

500000 500000
75240 330 21 5 271800 443040 34650 1425 426400 96 245088 3612 195228 239360 253368 864 281952 264420 13 120 8 319680 14 272 475488 400608 24 18 7 2 314600 239040 10 315 444080 495360 16 2 1344 197100 455940 131328 192192 24 1078 78 12 118080 17 460404 48 4860 470610 238 22 34020 440880...

output:

1551726811
22117135885
893331479
2192037533
182212865
1794926131
14593765330
7444229577
429529666
29302183719
14838550719
11184431636
2793344
21471002240
1609459864
6015467429
8828414109
8786067855
205457732
29990502
276561422
9418985151
857629317
2814223269
3680045716
14793644663
10764646564
122274...

result:

ok 500000 lines

Test #8:

score: 0
Accepted
time: 1800ms
memory: 81028kb

input:

500000 500000
293216 401580 21 489510 4 13 1 2250 48 792 400 20 735 405132 10416 197600 227136 588 1 24 6 1820 319500 352170 179550 348075 100 20 357 132300 13 389232 202950 479700 240 1 2002 190512 792 4 14 125280 9 740 178848 1 231 10 384048 20 132 289680 404976 33264 468600 15 20 46 3 1224 23 12 ...

output:

2294436954
11097169278
19481747647
8364608589
1952685207
1897724371
1515941854
28651891
11208151600
59254107
4069249142
32924950699
1897820617
6328784084
11574449103
49051442
4602807555
16031851431
2729156
558089688
2595010956
3057206770
5605068218
8887867564
224740298
1268503891
1283163416
33036442...

result:

ok 500000 lines

Test #9:

score: 0
Accepted
time: 1800ms
memory: 80932kb

input:

500000 500000
2 7 8640 625 360672 15 854 9 8 720 16 18 4 13 17 21 48 308000 364 240768 13 4 9 21 630 65 658 11 3 105300 9 187572 11 36 6 180 13 124 15 22 96 150 504 69 3 4 420 338184 11 20 30 16 15 3 160 2 210 42 10440 2300 1395 10 3 21 61600 21 19 14 14 288 50 24 184 3 9 14 193500 208 3 135 9 4 9 2...

output:

12834239819
952270700
3559642176
3719392156
14064147236
596610924
16170422
239663186
3289612685
7113346
3208509365
5807881199
1407475885
252636302
1035765038
2176803596
176854212
1453399377
6631462762
66137118
112934517
14739014044
14185310297
5338409576
232566088
409509279
5626354025
190229181
4783...

result:

ok 500000 lines

Test #10:

score: 0
Accepted
time: 2213ms
memory: 80800kb

input:

500000 500000
177300 469504 114210 7 409920 243576 459108 172320 354858 492768 136136 5 28160 216576 105984 368760 280566 420750 250140 443352 416944 438750 221958 204050 389220 86184 9 397992 133536 441140 95088 74700 5 213000 207024 266700 64064 337280 474810 280280 378420 101700 117096 458304 166...

output:

2013515378
8394300595
650360302
2623560536
646046271
1816405584
6494426266
8216962673
2318932623
257515701
29175545
6681368660
1869489438
6865692070
722525753
14282130741
1113759102
483840974
2621274645
4126477360
10233825013
141777098
40582729
564292932
5996890023
560426065
1808482977
504506815
603...

result:

ok 500000 lines

Test #11:

score: 0
Accepted
time: 2168ms
memory: 80812kb

input:

500000 500000
450360 310905 419280 497120 3 10 5 2 405540 454500 55776 189520 191760 286752 494208 375760 363285 8 382128 1 14160 7 9 467400 451050 2 80976 7 9 489960 394956 9 476640 219384 268260 359480 8 281340 156880 181050 4 5 45 279620 3 196420 24 346176 279450 2 3 137400 4 5 382720 141300 4254...

output:

5967351842
19245444195
13083246305
773492428
10755940011
19088814
1449499862
81512276
1046722303
214267317
961371074
17944447594
20977758434
4907908978
21667759
3556536754
17342450954
31155793106
3938552965
696573829
12513517
27228696212
9470612621
7404503836
600754540
104654307
10570342573
12992928...

result:

ok 500000 lines

Test #12:

score: 0
Accepted
time: 2037ms
memory: 80956kb

input:

500000 500000
395280 10 4 9860 438570 136224 217500 342720 449388 10 357952 3 451878 389536 439460 443360 31980 256542 345774 9 8 3 489972 8 8 7 1 7 205800 1 431024 70070 201280 123888 161190 473970 217035 3 115830 118500 6 9 300762 6 339048 2 379134 7 104 156464 10 456876 38304 65790 2 4 8 194760 4...

output:

7393910829
23288846347
2797314511
18384959675
3058876689
1133315387
1188388448
18258675244
3323493243
4334276425
1224425836
1946344666
10652983725
4226784202
8757850354
1071319090
1971854481
10402744477
7148659075
1895798098
28032784559
15081239036
173184791
344965102
17936964456
17022007859
2456130...

result:

ok 500000 lines

Test #13:

score: 0
Accepted
time: 1918ms
memory: 83036kb

input:

500000 500000
6 9 4 10 2 5400 8 9 7 9 36 8 9 5 10 8 9 1 249240 404200 113940 10 273600 128064 9 4 139500 5 10 8 10 3 47736 6 372708 10 9 3 9 4 5 282420 76296 198 415950 3 4 126336 5 60960 120120 133644 4 1872 4 4 245952 3 3 2 8 1 7 64980 3 7 1 8 3 10 494960 15912 9 1 288624 10 6 430650 3 8 4 5 10 2 ...

output:

5806303062
113310254
1313799305
6265160826
27610843489
33094537186
4634025747
788429818
20605673284
896974489
3268852952
24421413042
6374595663
7152983541
763367738
39294108054
14750914391
35616459262
1782085570
21146246168
2048685140
2744744235
739158298
14813706733
2016903280
1674245043
90159092
6...

result:

ok 500000 lines

Test #14:

score: 0
Accepted
time: 2037ms
memory: 83040kb

input:

500000 500000
243516 5 486504 111240 66 8 458436 7 4 44226 7 316134 118140 9 9 112336 195600 3 4 446880 3 10 365904 205380 36624 2 6 30960 4 2 315040 96720 369765 5 184992 311832 16464 2 337584 9 2 85824 112112 176592 219936 411300 261960 349920 146850 5 78320 365112 339024 8 388908 2 475020 3 14876...

output:

4091885310
34437051
23020991054
62280
10218633998
7029286644
13679178334
3638710636
9252276712
433722312
2773140141
21900060760
23994166660
255724269
15947810359
4901128059
1487460081
13440532912
748230651
9749475534
2145004585
439166631
12328577193
8393349444
29223498776
47880863881
9631461538
9501...

result:

ok 500000 lines