-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2124 lines (1100 loc) · 69.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>REN Tingxu</title>
<link rel="alternate" href="/atom.xml" title="REN Tingxu">
<meta name="HandheldFriendly" content="True">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- meta -->
<!-- link -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/waves.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css">
<link rel="shortcut icon" type="image/x-icon" href="/images/webicon.png">
<link rel="stylesheet" href="/style.css">
<script>
function setLoadingBarProgress(num) {
document.getElementById('loading-bar').style.width=num+"%";
}
</script>
</head>
<body>
<header class="l_header pure">
<div id="loading-bar-wrapper">
<div id="loading-bar" class="pure"></div>
</div>
<div class='wrapper'>
<div class="nav-main container container--flex">
<a class="logo flat-box" href='/' >
REN Tingxu
</a>
<div class='menu navgation'>
<ul class='h-list'>
<li>
<a class="nav flat-box" href="/"
id="home">
<i class='fas fa-grin fa-fw'></i> recent
</a>
</li>
<li>
<a class="nav flat-box" href="/categories/"
rel="nofollow"
id="categories">
<i class='fas fa-folder-open fa-fw'></i> Categories
</a>
</li>
<li>
<a class="nav flat-box" href="/tags/"
rel="nofollow"
id="tags">
<i class='fas fa-hashtag fa-fw'></i> Tags
</a>
</li>
<li>
<a class="nav flat-box" href="/archives/"
rel="nofollow"
id="archives">
<i class='fas fa-archive fa-fw'></i> archieves
</a>
</li>
<li>
<a class="nav flat-box" href="/about/"
rel="nofollow"
id="about">
<i class='fas fa-info-circle fa-fw'></i> about
</a>
</li>
</ul>
</div>
<div class="m_search">
<form name="searchform" class="form u-search-form">
<input type="text" class="input u-search-input" placeholder="Search" />
<i class="icon fas fa-search fa-fw"></i>
</form>
</div>
<ul class='switcher h-list'>
<li class='s-search'><a class="fas fa-search fa-fw" href='javascript:void(0)'></a></li>
<li class='s-menu'><a class="fas fa-bars fa-fw" href='javascript:void(0)'></a></li>
</ul>
</div>
<div class='nav-sub container container--flex'>
<a class="logo flat-box"></a>
<ul class='switcher h-list'>
<li class='s-comment'><a class="flat-btn fas fa-comments fa-fw" href='javascript:void(0)'></a></li>
<li class='s-toc'><a class="flat-btn fas fa-list fa-fw" href='javascript:void(0)'></a></li>
</ul>
</div>
</div>
</header>
<aside class="menu-phone">
<header>
<nav class="menu navgation">
<ul>
<li>
<a class="nav flat-box" href="/"
id="home">
<i class='fas fa-grin fa-fw'></i> recent
</a>
</li>
<li>
<a class="nav flat-box" href="/categories/"
rel="nofollow"
id="categories">
<i class='fas fa-folder-open fa-fw'></i> Categories
</a>
</li>
<li>
<a class="nav flat-box" href="/tags/"
rel="nofollow"
id="tags">
<i class='fas fa-hashtag fa-fw'></i> Tags
</a>
</li>
<li>
<a class="nav flat-box" href="/archives/"
rel="nofollow"
id="archives">
<i class='fas fa-archive fa-fw'></i> Archives
</a>
</li>
<li>
<a class="nav flat-box" href="/about/"
rel="nofollow"
id="about">
<i class='fas fa-info-circle fa-fw'></i> about
</a>
</li>
</ul>
</nav>
</header>
</aside>
<script>setLoadingBarProgress(40);</script>
<div class="l_body nocover">
<div class='body-wrapper'>
<div class='l_main'>
<section class="post-list">
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/12/03/Attentions/">
Attentions!
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-12-03</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/注意点/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>注意点</p>
</a>
</div>
<div class="new-meta-item top-post">
<a class='notlink'>
<i class="fas fa-angle-double-up" aria-hidden="true"></i>
<p>Top</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<div class="readmore">
<a href="/2019/12/03/Attentions/" class="flat-box">
<i class="fas fa-book-open fa-fw" aria-hidden="true"></i>
Read More
</a>
</div>
</div>
</section>
</article>
</div>
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/12/08/LOJ2541-「PKUWC2018」猎人杀/">
LOJ2541. 「PKUWC2018」猎人杀
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-12-08</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/数学/概率/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>数学 / 多项式 / 概率</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<blockquote>
<p>题目链接:<a href="https://loj.ac/problem/2541" target="_blank" rel="noopener">LOJ2541</a></p>
</blockquote>
<h1 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h1><p>先尝试dp啊,通分啊搞一搞,发现无论怎么搞都会很多很难受的分母,搞不出来,如果可以把分母的形式简化就好了<br>本题第一个想法,也是最大的思维难点:</p>
<blockquote>
<p>发现可以将问题转化为:每一个人可以选多次,问1号最后一个被选的概率,这样与原问题是等价的</p>
</blockquote>
<p>感性考虑一下,如果一个人多次被选,大不了这几次都不算,没啥影响。具体证明也不难,设$P$为当前状态下第i个人被选的概率,$S = \sum w_i$,$D= \sum_{i\ is\ already\ dead} w_i$,根据题意显然有<br>$$ P = \frac{w_i}{S - D} $$<br>同时,如果我们用转换后的题意,当前可以选择杀死第i个人,也可以选择杀一个死者,如果鞭尸的话下一步的状态和当前完全相同,也就是<br>$$ P = \frac{w_i}{S} + \frac{D}{S}P $$<br>将这个关于$P$的方程解出来就得到原题的式子了</p>
<p>这样分母就统一了,优点是可以容斥了,考虑枚举集合T表示在在1号之后被杀死的人,枚举i表示第i+1枪把1号杀死了<br>$$<br>ans = \sum(-1)^{|T|}\sum_{i=0}^{+\infin}(\frac{S - S_T - w_1}{S})^i\frac{w_1}{S} \\<br>= \sum(-1)^{|T|}\frac{1}{1-\frac{S - S_T - w_1}{S}}\frac{w_1}{S}\\ = \sum(-1)^{|T|}\frac{w_1}{S_T + w_1}<br>$$<br>于是可以使用背包dp,f[i][S]表示考虑前i个,$\sum w$恰好为S的带上容斥系数的方案数,有$$<br>f[i][x] = f[i-1][x] - f[i-1][x - w[i]]<br>$$<br>构造生成函数$\Pi(1-x^{w_i})$,可以发现f[S]就是展开式中$x^S$的系数<br>用分治法将该式展开,每次二分找到一个两边次数和最接近的分界点,递归处理两边,然后NTT卷积起来,可以保证复杂度是$O(nlog^2n)$的</p>
<p>统计答案时枚举$S_T$,统计上面推出来的式子即可<br>
<div class="readmore">
<a href="/2019/12/08/LOJ2541-「PKUWC2018」猎人杀/" class="flat-box">
<i class="fas fa-book-open fa-fw" aria-hidden="true"></i>
Read More
</a>
</div>
</div>
<div class="full-width auto-padding tags">
<a href="/tags/NTT/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>NTT</a>
<a href="/tags/概率/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>概率</a>
<a href="/tags/容斥/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>容斥</a>
</div>
</section>
</article>
</div>
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/10/11/CF1229F-Mateusz-and-Escape-Room/">
CF1229F. Mateusz and Escape Room
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-10-11</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/动态规划/凸包/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>动态规划 / 凸包</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<blockquote>
<p>题目链接:<a href="http://codeforces.com/contest/1229/problem/F" target="_blank" rel="noopener">CF1229F</a></p>
</blockquote>
<h1 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h1><p>设第i个scale向第i-1个scale移动了$x_i$个硬币,为负则代表向左移动,显然可以列出方程组<br>$$<br>l_i - a_i \le x_{i+1} - x_i \le r_i - a_i<br>$$<br>要求$\sum|x_i|$最小<br>首先考虑对于一个固定的$x_1$如何计算这个最小值。考虑动态规划,令$f[i][x]$表示考虑了前i个,第$x_i$的值为j,最少要移动的硬币数,那么显然有如下转移$$<br>f[i][j] = min{f[i-1][j - r_i + a_i…j - l_i + a_i]} + j<br>$$<br>可以将$f[i]$值看成是关于$x_i$的一个函数$f_i(x)$,自变量是$x_i$的取值,因变量是最小移动数,我们可以维护这个函数,考虑如何从$f_i(x)$转移到$f_{i+1}(x)$<br>每个位置新的函数值是之前的某个区间的最小值再加上横坐标,而这个区间是随着自变量一个一个向右平移的,因此可以把操作看成是以下操作的组合</p>
<ol>
<li>整体左右移动</li>
<li>$ f(x) = min{f(x…x+t)} $</li>
<li>$ f(x) += |x| $</li>
</ol>
<p>可以发现如果原函数是一个单峰函数,那么进行这些操作后仍是单峰函数。该函数的初值是$f(x_1) = |x_1|,\quad f(x) = inf\ (x != x_1) $为开口向上的单峰函数。由这一点又可以发现,第2个操作其实相当于整体左右移动后,再将最小值的长度加长<br>因此每次维护可以简化为如下内容</p>
<ol>
<li>将上升部分右移$r_i - a_i$</li>
<li>将下降部分右移$l_i - a_i$</li>
<li>$ f(x) += |x|$</li>
</ol>
<p>如果维护每个每条斜率相同的线段,那么这些线段的斜率是单调增的,且第3个操作只会将y轴左边的线段斜率减一,右边的线段斜率加一。官方题解使用平衡树维护这些线段的斜率和长度,但实际上只需要一个priority_queue,维护所有斜率变化的转折点。由于斜率每次只会变化1,且恒为整数,因此可以维护每一个整数斜率的转折点,如果一个点的斜率变化超过1,那么这个点会插入队列多次,相当于在这个点斜率多次变化1。</p>
<p>用两个优先队列维护斜率变化的转折点(可重复),对于第1、2个操作,记录左右部分分别移动的距离,可以方便获取实际位置,对于第3个操作,只会涉及到两个队列之间之多一个元素从一个到另一个里面,需要注意穿过y轴的那个线段,他的斜率变化比较特殊,每次都需要新加入转折点。</p>
<p>当转移完所有$x_i$后,此时的$f(x_1)$就是要求的最小值(因为构成循环)</p>
<p>这样对于一个固定的$x_1$,可以$O(nlogn)$求出最小值,然而枚举$x_1$仍需要$O(n)$的时间。令$F(x)$表示如果$x_1 = x$,那么如此转移一轮后得到的最小值。那么可以证明</p>
<blockquote>
<p>$F(x)$是一个开口向上的单峰函数</p>
</blockquote>
<p>具体证明不会,但可以猜到。。。<br>我的想法是,固定$x_1$后可以得到最优的一组$x_i$,将他们画成一条折线,如果控制$x_{i+1}-x_i$不变,改变$x_1$可以将它上下平移。要求minimize$\sum|x_i|$,也就是x轴要在这些点纵坐标的中位数处,随着折线的上下平移,或者看成x轴的上下平移,这个绝对值之和显然是一个单峰函数<br>但这只是不严谨的理解方式。。。</p>
<p>由这条性质可以三分$x_1$的值,然后跑一遍维护的过程求出最小值更新答案,时间复杂度$ O(nlognlogS) $,其中$S = \sum a_i$<br>
<div class="readmore">
<a href="/2019/10/11/CF1229F-Mateusz-and-Escape-Room/" class="flat-box">
<i class="fas fa-book-open fa-fw" aria-hidden="true"></i>
Read More
</a>
</div>
</div>
<div class="full-width auto-padding tags">
<a href="/tags/优先队列/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>优先队列</a>
<a href="/tags/凸包维护/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>凸包维护</a>
<a href="/tags/三分/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>三分</a>
</div>
</section>
</article>
</div>
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/10/03/数论定理整合/">
数论定理整合
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-10-03</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/数学/数论/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>数学 / 数论</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<div class="readmore">
<a href="/2019/10/03/数论定理整合/" class="flat-box">
<i class="fas fa-book-open fa-fw" aria-hidden="true"></i>
Read More
</a>
</div>
</div>
<div class="full-width auto-padding tags">
<a href="/tags/数论/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>数论</a>
<a href="/tags/定理/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>定理</a>
</div>
</section>
</article>
</div>
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/09/27/CF1205E-Expected-Value-Again/">
CF1205E. Expected Value Again
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-09-27</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/其他/性质/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>其他 / 性质</p>
</a>
</div>
</div>
<hr>
</div>
</section>
<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<blockquote>
<p>题目链接:<a href="https://codeforces.com/contest/1205/problem/E" target="_blank" rel="noopener">CF1205E</a></p>
</blockquote>
<h1 id="Solution"><a href="#Solution" class="headerlink" title="Solution"></a>Solution</h1><p>令$f(s, i)$表示字符串s中是否有一个长度为j的前后缀,则答案为<br>$$<br>E((\sum_{i=1}^{n-1}f(s, i))^2) \\<br>= \sum_{i=1}^{n-1}\sum_{j=1}^{n-1}E(f(s, i) * f(s, j)))<br>$$<br>表示的意义就是对于任意i和j,求出一个字符串同时有i和j长度的前后缀的期望,也就是有多少个字符串同时有长度为i和j的前后缀,再除以$k^n$<br>重点就是这样一个性质</p>
<blockquote>
<p>一个字符串同时有长度为$n-i$和$n-j$的前后缀的期望是<br>$$(\frac{1}{k})^{n-max(gcd(i, j),\ i + j - n)}$$</p>
</blockquote>
<p>下面来证明这个性质</p>
<p>首先,如果有长度为$n-i$的前后缀,那么i一定是一个循环节。这一点容易证明。现在i和j都是循环节,所以$gcd(i, j)$也是循环节,一个循环节内的字符可以任意取,剩下的都是固定的,除以$k^n$得到max的前一部分</p>
<p>然后,我们有一种感觉,如果$i+j$足够长,那么两个循环节从第二次出现开始不一定会有许多重合的位置,或许gcd相对苛刻了一些。换句话说,如果该字符串无限长,那么一定是gcd为循环节,但长度是有限的,有特殊情况需要考虑。</p>
<p>举几个例子,用相同的字母表示必须相同的位置,X表示任意<br>一个长度为10的字符串,i=7,j=8<br>AAAXXXXAAA<br>一个长度为11的字符串,i=10,j=3<br>AAXAAXAAXAA<br>显然他们的循环节都不是gcd</p>
<p>如果$i+j\leq n$,那么答案显然就是gcd,画一个图,较长串第二次出现可以看成一个较短串,这个完整的较短串和全部由较短串拼出的串的对应部分相等,差的部分是循环节,可以递归得到gcd(两数gcd等于差的gcd)</p>
<p>否则,$i+j\gt n$,不同之处在于较长串第二处出现无法看成一个完整的较短串。不妨令$ i > j $,第二次循环时可以看成一个j,这个j和 完全由j拼成的串 的对应位置产生错位,在j内部产生循环,递归到gcd,如果i后面的那个j超过n的部分段于gcd,那么循环节可以作用在整个j里,成为真正的循环节,否则它是假的循环节,因为无法扩展完整个j,剩下的无法扩展的部分就是$i + j - n - gcd(i, j)$ 这部分作为j这个循环节的一部分可以随便取,再算上gcd可以随便选,结果就是$max(gcd(i, j),\ i + j - n)$</p>
<p>下面考虑怎么算,枚举$d = gcd(i, j), s = i + j$,转化为求多少对i和j满足定义,注意$ 1 \leq i, j < n $<br>$$<br>f(d) = \sum_{i=1}^{min(n - 1, s - 1)}[gcd(i, s - i) = d] \\<br>F(d) = \sum_{d|t} f(t) = min(s - 1, n - 1) / t;<br>$$<br>$$<br>f(d) = \sum_{d|t}\mu(\frac{t}{d})F(t)<br>$$<br>代码中,由于$ d | t | s $,所以先枚举d,再枚举的是t / d,最后枚举s,复杂度$O(nlog^2n)$,注意i,j的范围<br>
<div class="readmore">
<a href="/2019/09/27/CF1205E-Expected-Value-Again/" class="flat-box">
<i class="fas fa-book-open fa-fw" aria-hidden="true"></i>
Read More
</a>
</div>
</div>
<div class="full-width auto-padding tags">
<a href="/tags/莫比乌斯反演/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>莫比乌斯反演</a>
<a href="/tags/性质/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>性质</a>
<a href="/tags/循环节/" rel="nofollow"><i class="fas fa-hashtag fa-fw"></i>循环节</a>
</div>
</section>
</article>
</div>
<div class='post-wrapper'>
<article class="post reveal ">
<section class='meta'>
<div class="meta" id="header-meta">
<h2 class="title">
<a href="/2019/09/18/BZOJ1566-NOI2009-管道取珠/">
BZOJ1566 [NOI2009]管道取珠
</a>
</h2>
<div class='new-meta-box'>
<div class='new-meta-item author'>
<a href="http://rentingxutx.github.io" rel="nofollow">
<i class="fas fa-user" aria-hidden="true"></i>
<p>rtxxx</p>
</a>
</div>
<div class="new-meta-item date">
<a class='notlink'>
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
<p>2019-09-18</p>
</a>
</div>
<div class='new-meta-item category'>
<a href='/categories/动态规划/计数dp/' rel="nofollow">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<p>动态规划 / 计数dp</p>
</a>
</div>
</div>
<hr>
</div>
</section>