QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644000#3060. Cumulative CodeRyan123RE 2ms3964kbC++142.0kb2024-10-16 09:28:472024-10-16 09:28:47

Judging History

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

  • [2024-10-16 09:28:47]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3964kb
  • [2024-10-16 09:28:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = (1 << 15) + 5;

typedef long long LL;
#define int LL

int pk[2][N], pb[2][N];
int cnt;

//rt_now = k * rt + b
void dfs1(int dep, int tp, int k, int b, int id){
	if(dep == 1)return ;
	
	dfs1(dep - 1, 1, k << 1, b << 1, id);
	cnt ++, pk[id][cnt] = k, pb[id][cnt] = b;
	if(tp == 1){
		dfs1(dep - 1, 1, k << 1, b << 1 | 1, id);
		cnt ++, pk[id][cnt] = k, pb[id][cnt] = b;
	}
	else {
		cnt ++, pk[id][cnt] = k << 1, pb[id][cnt] = b << 1 | 1;
		dfs1(dep - 1, 0, k << 1, b << 1 | 1, id);
	}
}

LL pK[2][N], pB[2][N];

int HF = 0;

LL dfs(int dep, int tp, int rt, int a, int d){
	if(dep <= HF) return pK[tp][a] * rt + pB[tp][a];
	
	LL ans = 0;
	
	int szl = (1 << (dep - 1)) - 2;
	if(a <= szl)return dfs(dep - 1, 1, rt << 1, a, d);
	else {
        // int t1 = a % d;
		// int t = szl - (szl % d - a % d + d) % d;
        int t = a - (a - szl + d - 1) / d * d;
        
        if(t > 0)ans += dfs(dep - 1, 1, rt << 1, t, d);
	}
	if((szl + 1) % d == a % d)ans += rt;
	
	if(tp == 1){
		if(szl + 2 <= a)ans += dfs(dep - 1, 1, rt << 1 | 1, a - szl - 1 - (a >= 2 * szl + 2) * d, d);
		if((2 * szl + 2) <= a && (2 * szl + 2) % d == a % d)ans += rt;
	}
	else {
		if(szl + 2 <= a && (szl + 2) % d == a % d)ans += rt << 1 | 1;
		if(szl + 3 <= a)ans += dfs(dep - 1, 0, rt << 1 | 1, a - szl - 2, d);
	}
	
	return ans;
}

int a, m, d;

signed main(){
	int n, q;
	// scanf("%d%d", &n, &q);
    scanf("%lld%lld", &n, &q);
	HF = n / 2;
	cnt = 0, dfs1(HF, 1, 1, 0, 1);
	cnt = 0, dfs1(HF, 0, 1, 0, 0);

	for(int TT = 1; TT <= q; TT ++){
		// scanf("%d%d%d", &a, &d, &m);
        scanf("%lld%lld%lld", &a, &d, &m);
        

		for(int i = 0; i <= 1; i ++) for(int j = 1; j <= cnt + 1; j ++){
            pK[i][j] = ((j > d) ? pK[i][j - d] : 0) + pk[i][j];
            pB[i][j] = ((j > d) ? pB[i][j - d] : 0) + pb[i][j];
        }

		printf("%lld\n", dfs(n, 0, 1, a + (m - 1) * d, d)   
		    - ((a > d) ? dfs(n, 0, 1, a - d, d) : 0));
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 5
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1

output:

2
2
1
3
3

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

4 4
2 1 5
4 4 3
4 8 1
10 3 2

output:

18
15
5
13

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

7 1
1 1 125

output:

4031

result:

ok single line: '4031'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

2 1
1 1 1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

3 32
1 5 1
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 4 1
1 4 2
2 5 1
2 1 1
2 1 2
2 1 3
2 1 4
2 2 1
2 2 2
2 3 1
2 3 2
3 5 1
3 1 1
3 1 2
3 1 3
3 2 1
3 2 2
4 5 1
4 1 1
4 1 2
5 5 1

output:

2
2
4
5
8
11
2
3
6
2
5
2
5
2
2
3
6
9
2
5
2
5
1
1
4
7
1
4
3
3
6
3

result:

ok 32 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

4 282
1 13 1
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 1 11
1 1 12
1 1 13
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 4 1
1 4 2
1 4 3
1 4 4
1 5 1
1 5 2
1 5 3
1 6 1
1 6 2
1 6 3
1 7 1
1 7 2
1 8 1
1 8 2
1 9 1
1 9 2
1 10 1
1 10 2
1 11 1
1 11 2
1 12 1
1 ...

output:

4
4
8
10
15
20
22
23
26
32
38
41
48
55
4
6
11
12
18
21
28
4
9
10
16
23
4
9
15
22
4
6
9
4
5
12
4
7
4
10
4
10
4
7
4
11
4
11
4
4
6
11
16
18
19
22
28
34
37
44
51
4
9
11
14
20
27
4
9
12
15
4
6
12
4
5
12
4
7
4
10
4
10
4
7
4
11
4
11
2
2
7
12
14
15
18
24
30
33
40
47
2
7
8
14
17
24
2
4
10
17
2
3
6
2
5
12
2
8...

result:

ok 282 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

5 268
26 16 1
10 26 1
13 22 1
3 6 2
19 3 4
20 15 1
25 5 1
15 10 1
1 23 2
13 19 1
8 1 8
20 22 1
9 18 1
27 21 1
8 11 2
23 14 1
25 10 1
19 9 2
15 21 1
9 5 2
11 25 1
12 16 2
11 8 3
15 6 1
9 25 1
20 19 1
2 15 1
28 18 1
7 4 1
4 24 2
12 2 7
20 1 5
7 3 5
26 3 2
16 3 4
15 1 7
6 1 3
2 1 25
12 2 6
4 2 12
21 1 ...

output:

14
5
5
14
41
13
14
1
15
5
55
13
10
7
16
3
14
21
1
12
11
26
24
1
10
13
8
15
2
24
54
42
21
29
29
60
16
194
47
96
57
166
95
89
171
125
21
21
122
76
36
112
44
9
71
104
87
18
96
32
21
12
133
89
98
15
19
56
26
52
14
27
46
34
51
47
5
36
39
72
28
65
25
42
29
14
35
33
41
16
56
18
17
17
22
72
18
32
32
111
46
...

result:

ok 268 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

6 267
54 29 1
48 14 1
21 54 1
46 50 1
44 26 1
20 48 1
37 40 1
47 11 1
16 40 2
15 39 1
1 25 2
19 12 2
47 32 1
19 9 5
5 52 2
18 4 6
41 32 1
32 18 1
8 33 2
9 40 2
9 40 2
38 58 1
19 37 2
46 55 1
2 51 2
43 8 2
12 40 2
11 11 5
13 10 5
54 11 1
2 2 29
27 1 25
4 1 23
17 1 21
11 1 11
46 1 12
18 3 6
47 3 3
7 1...

output:

14
7
10
6
27
21
25
3
35
2
39
22
3
70
47
76
26
3
44
46
46
12
36
6
45
41
48
82
111
14
464
391
329
320
155
210
91
60
802
176
360
19
186
438
585
184
199
504
92
135
119
61
45
84
491
503
72
235
358
316
162
64
100
12
177
95
145
35
93
105
96
57
36
90
123
44
254
65
12
130
69
130
231
616
130
109
30
71
152
68
...

result:

ok 267 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

7 290
72 99 1
109 61 1
22 92 2
71 44 1
1 33 2
12 94 1
29 96 1
67 63 1
95 72 1
103 124 1
106 71 1
69 55 2
5 77 1
32 83 1
5 19 4
22 30 2
112 118 1
50 60 1
18 90 1
107 5 2
42 110 1
71 114 1
100 119 1
33 26 1
9 30 3
17 111 1
54 34 3
62 83 1
9 100 2
87 19 1
70 1 26
4 5 15
57 3 17
85 4 11
42 1 73
4 1 97
2...

output:

50
29
69
12
52
35
9
24
3
14
29
112
33
40
116
31
15
45
18
74
43
12
57
40
125
36
162
2
63
54
875
410
617
512
2453
2895
1258
1839
505
215
2717
858
2218
1977
1535
244
700
1959
994
1414
1111
2026
1382
813
92
1848
196
923
45
1106
176
469
293
693
1337
644
1539
526
1526
426
35
112
786
875
90
362
374
133
616...

result:

ok 290 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

8 269
224 150 1
210 165 1
76 146 2
60 8 22
126 158 1
53 105 2
67 234 1
211 162 1
156 14 4
91 36 3
232 131 1
89 88 2
65 163 1
244 94 1
20 91 2
75 143 2
94 81 1
19 40 6
112 67 3
10 29 8
17 8 27
44 97 3
236 161 1
68 25 1
160 44 3
29 243 1
126 84 1
204 226 1
192 86 1
65 219 1
195 1 24
213 1 18
174 1 58
...

output:

15
58
55
1416
2
31
81
117
269
149
122
141
80
125
161
202
5
524
217
450
2090
116
123
81
282
17
2
115
7
80
2005
1346
4294
218
1393
471
5045
12854
4377
5405
809
1501
11704
1009
3404
1184
5279
5647
1250
339
1764
4283
8546
4385
1603
10152
697
5578
1653
1226
4663
4994
7297
5667
268
121
925
5549
72
1782
43...

result:

ok 269 lines

Test #11:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

9 283
55 249 2
27 504 1
91 192 2
389 419 1
45 31 5
482 15 2
287 320 1
51 434 2
192 268 2
353 311 1
281 366 1
114 384 2
383 466 1
248 346 1
368 382 1
80 347 2
382 118 1
241 168 2
362 351 1
111 188 2
124 468 1
368 65 2
108 440 1
30 179 1
371 38 3
225 110 3
94 491 1
282 215 2
388 68 1
252 178 2
81 1 24...

output:

346
135
274
225
518
500
12
390
419
108
99
409
3
191
110
383
6
304
219
359
19
228
38
16
232
426
9
451
225
40
29166
12841
169
23358
13064
33228
29580
14359
8642
15410
24227
7855
13553
7203
53452
1608
23094
5207
13875
444
20483
1116
11536
34144
24314
5483
3549
30876
10034
23476
5866
7404
6779
6217
1150...

result:

ok 283 lines

Test #12:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

10 271
610 694 1
97 899 1
461 310 2
513 780 1
80 834 1
673 407 1
122 920 1
490 303 1
247 734 2
865 60 1
576 669 1
662 765 1
844 205 1
1007 590 1
1015 669 1
11 321 3
533 315 2
613 676 1
119 923 1
973 639 1
223 194 3
38 727 1
624 551 1
500 537 1
7 404 1
347 414 1
965 946 1
463 410 2
134 529 2
539 481 ...

output:

409
140
596
384
276
212
143
94
569
236
400
422
233
63
127
447
662
102
143
249
1082
66
206
382
64
85
497
661
494
902
29529
103680
111203
62141
85155
103606
13535
183272
29440
39352
90030
63722
23614
107500
94500
133213
129603
4346
47522
51821
6844
199856
26147
37081
24740
109682
42266
84025
70876
146...

result:

ok 271 lines

Test #13:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

11 287
1995 458 1
1579 1480 1
520 1923 1
406 1747 1
1334 697 2
317 136 4
218 1531 1
849 330 1
1434 1666 1
1543 725 1
502 659 3
1206 194 2
1921 697 1
1618 1102 1
1764 375 1
980 691 1
1057 908 1
270 1741 1
98 1130 2
1871 612 1
578 1113 1
1771 275 1
355 135 10
845 1736 1
1037 1456 1
1910 375 1
874 1431...

output:

1011
907
642
614
973
1438
283
725
435
224
1523
1677
992
917
238
758
776
72
741
980
657
238
3885
724
385
990
182
855
545
657
244500
134914
147176
15945
449222
812153
185316
53530
415863
402117
564968
16593
72616
354194
205235
326339
273978
331923
345966
222126
36847
50022
416720
103366
87374
443986
2...

result:

ok 287 lines

Test #14:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

12 276
863 1831 1
1619 2607 1
3811 3252 1
3025 1920 1
534 1240 3
982 1637 2
1696 2405 1
754 2637 1
936 3943 1
3307 568 1
4075 3475 1
1413 1001 2
3366 2763 1
2241 1696 1
2033 181 10
509 1162 2
3030 810 2
3371 1563 1
3919 451 1
2383 1709 2
3831 1691 1
3018 1055 2
2762 328 4
3714 2569 1
444 2553 2
458 ...

output:

620
357
988
890
3516
1690
1449
303
1259
462
2043
3006
1866
792
11521
738
1814
933
2004
3667
1983
2486
4655
976
957
2473
775
514
3742
316
145074
2301556
38308
701585
128902
438274
39379
20056
60817
2594914
1301899
1588724
3078212
2104109
978120
763258
1683241
365433
4085082
34486
828306
1156781
11649...

result:

ok 276 lines

Test #15:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

13 296
8043 4170 1
5891 46 50
5809 1368 2
4887 7911 1
6035 6457 1
2953 3539 2
4104 607 6
5184 6772 1
4125 3406 2
3041 3930 1
6013 3784 1
6836 1486 1
6650 7295 1
3055 3481 2
5416 816 2
2663 3768 2
4166 7360 1
3608 3843 1
5711 7456 1
7824 2308 1
5109 132 18
5539 6456 1
6014 4917 1
7857 7459 1
722 4174...

output:

2029
138358
5592
1635
3558
1851
17269
3344
1751
702
3552
3758
463
3247
5206
6371
772
2951
1738
4004
42935
858
3552
4013
1114
1093
2903
3769
2460
4175
15073828
6739949
3628843
6742502
7197254
11727032
12287327
10961071
3451444
3468014
1274299
1468375
221279
7754952
1724777
555695
1839318
565831
89479...

result:

ok 296 lines

Test #16:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

14 297
6045 16104 1
13741 13527 1
13666 209 10
12305 1174 3
12448 5824 1
6803 7763 1
15590 7238 1
8068 9485 1
14588 10542 1
6 2681 3
10499 8725 1
9678 5958 2
2680 3115 2
10010 15419 1
5157 11358 1
4982 1780 3
11406 989 3
5143 8928 1
1590 7136 1
11299 7141 1
2990 1131 7
10913 10808 1
15726 13487 1
43...

output:

2804
7532
45497
11389
7208
5798
7994
3057
483
8175
6721
7260
7929
1649
5386
12298
14266
2691
2247
3460
30189
6825
8028
5621
6705
63755
49
31666
17044
5183
9088278
29271586
21926957
16049437
4097774
6723565
6628340
11459272
55357505
14933118
19425757
17315541
17747761
62723
53705271
4814873
9729996
2...

result:

ok 297 lines

Test #17:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

15 300
31349 1802 1
22259 22587 1
23462 22537 1
9448 7002 3
432 25131 2
8518 22188 1
10019 5168 2
3289 3395 7
29294 7961 1
26410 13056 1
20994 11608 2
6214 1102 25
30989 24532 1
29958 1183 1
21993 1614 3
5348 10132 3
17993 20118 1
22679 23406 1
28938 19903 1
29361 13516 1
15347 1745 9
3134 7927 3
13...

output:

16030
6879
14059
25485
9212
10322
16693
49619
15516
3698
29784
191394
3984
15682
19430
18334
12691
13863
15427
15533
73632
21552
18107
51329
13360
6607
24803
15579
52393
4796
20820162
11672856
30347711
56123777
35438582
101465446
184550113
126594342
63636501
518446
32137284
8990272
143355355
3793255...

result:

ok 300 lines

Test #18:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

16 300
33941 38966 1
4948 58924 1
14760 63396 1
61777 11565 1
7718 59747 1
21890 52999 1
43463 21733 2
18253 31482 2
14033 41634 1
36579 14551 1
38701 48483 1
14074 53430 1
31632 2657 6
26541 64425 1
43328 6610 2
39613 28491 1
28320 6421 1
4697 24666 1
51923 38690 1
33259 9737 2
34789 48429 1
9745 6...

output:

24870
17622
5018
31829
18315
5464
35421
39292
19894
25530
13030
310
123197
23021
56086
26288
5866
8779
29366
30222
25083
18821
6822
51467
29665
87441
28901
24192
27354
24542
229436129
221024210
220810561
795395977
255538006
66959184
84938837
477741039
381332494
737530682
324426576
25651882
98462624
...

result:

ok 300 lines

Test #19:

score: 0
Accepted
time: 2ms
memory: 3768kb

input:

17 300
84294 406 7
47966 52379 1
106009 77845 1
23688 27301 3
64980 65048 1
47846 44902 2
23076 7086 14
25190 53684 1
54084 5167 9
87872 40413 2
70678 59170 1
95628 41599 1
118169 16539 1
122765 105758 1
55995 105201 1
88856 21979 2
67259 110586 1
41040 70240 1
26650 124323 1
123344 15591 1
95569 86...

output:

304463
22380
14817
117204
12253
67138
494327
39067
412950
31420
50438
28338
15577
63461
46768
74223
3098
43029
9857
63605
56662
49819
5552
52720
65171
64819
29655
55570
16312
43458
682926411
2230313325
172730241
168775
3904272858
1868044259
2753815266
515462719
414563614
1844384430
9218269
846515865...

result:

ok 300 lines

Test #20:

score: 0
Accepted
time: 2ms
memory: 3964kb

input:

18 300
158138 210076 1
78004 6013 24
214197 108715 1
182671 131026 1
72042 252245 1
131188 187365 1
206159 228628 1
215326 113321 1
33293 184998 2
87027 105509 1
176124 1506 20
92587 46741 3
86841 260938 1
54462 148700 1
203860 220741 1
150110 89788 1
176066 1038 23
72944 216364 1
30149 216888 2
218...

output:

3283
1957823
59543
111205
83548
24583
117077
119368
129342
87295
1323783
200737
5452
79153
116502
51532
1832266
83774
75063
47650
45646
188674
45781
31762
117626
73681
113079
43377
85631
104249
9518625733
2076150356
12903945629
8053846165
3528140061
2043882865
228590234
6475166632
3328227717
6912303...

result:

ok 300 lines

Test #21:

score: -100
Runtime Error

input:

19 300
306751 496908 1
154228 426522 1
444732 54452 1
88453 289952 1
230399 84205 3
357334 32383 6
396725 490232 1
43637 161459 1
60732 159421 3
176341 448840 1
281554 231306 1
84343 385533 2
277277 289596 1
240224 378049 1
319424 67779 1
231115 425112 1
404630 281168 1
489842 324804 1
348403 385536...

output:


result: