-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2067 lines (762 loc) · 252 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 class="theme-next gemini use-motion" lang="zh-Hans">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<link rel="stylesheet" media="all" href="/lib/Han/dist/han.min.css?v=3.3">
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=5.1.4">
<link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">
<meta name="keywords" content="Hexo, NexT" />
<link rel="alternate" href="/atom.xml" title="嗷嗷嗷's Blog" type="application/atom+xml" />
<meta name="description" content="算法竞赛, 数学, 怪物猎人(?)">
<meta property="og:type" content="website">
<meta property="og:title" content="嗷嗷嗷's Blog">
<meta property="og:url" content="http://aoudad.cn/index.html">
<meta property="og:site_name" content="嗷嗷嗷's Blog">
<meta property="og:description" content="算法竞赛, 数学, 怪物猎人(?)">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="嗷嗷嗷's Blog">
<meta name="twitter:description" content="算法竞赛, 数学, 怪物猎人(?)">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Gemini',
version: '5.1.4',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
duoshuo: {
userId: '0',
author: '博主'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="http://aoudad.cn/"/>
<title>嗷嗷嗷's Blog</title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">嗷嗷嗷's Blog</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">aoaoao's Blog</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br />
首页
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
标签
</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section">
<i class="menu-item-icon fa fa-fw fa-th"></i> <br />
分类
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
归档
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://aoudad.cn/2019/02/24/组队赛-Day1-E-CC的简单多项式/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="嗷嗷嗷">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="嗷嗷嗷's Blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/24/组队赛-Day1-E-CC的简单多项式/" itemprop="url">组队赛 Day1 E CC的简单多项式</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-24T20:18:16+08:00">
2019-02-24
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/组队赛/" itemprop="url" rel="index">
<span itemprop="name">组队赛</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body han-init-context" itemprop="articleBody">
<h2 id="题意链接"><a href="#题意链接" class="headerlink" title="题意链接"></a><strong>题意链接</strong></h2><p><a href="https://scut.online/contest/41/E" target="_blank" rel="noopener">https://scut.online/contest/41/E</a></p>
<h2 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a><strong>题意:</strong></h2><p>求那个奇怪的多项式卷积在 $x=1$ 时候的取值</p>
<h2 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a><strong>思路:</strong></h2><p>需要的技能点:积性函数前缀和,杜教筛<br>实际上就是求两个多项式的系数两两之间的gcd之和,因为求的是$h(1)$的值,所以将第二个多项式反过来也一样,也就是求 </p>
<script type="math/tex; mode=display">S = \Sigma_{i=1}^{n}\Sigma_{j=1}^ngcd(i^2,j^2)</script><p>其中 </p>
<script type="math/tex; mode=display">gcd(i^2,j^2)=gcd(i,j)^2</script><p>换个枚举顺序的话就是$gcd(i,j)^2$,所以就是求 </p>
<script type="math/tex; mode=display">\Sigma_{i=1}^{n}\Sigma_{j=1}^ngcd(i,j)^2</script><p>改为枚举gcd得到 </p>
<script type="math/tex; mode=display">\Sigma_{d=1}^nd^2\ \Sigma_{i=1}^{n/d}\ \Sigma_{j=1}^{n/d}[gcd(i,j)=1]</script><p>用莫比乌斯函数替换 </p>
<script type="math/tex; mode=display">\Sigma_{d=1}^nd^2\ \Sigma_{i=1}^{n/d}\ \Sigma_{j=1}^{n/d}\ \Sigma_{D|(i,j)} \mu(D)</script><p>枚举D得到 </p>
<script type="math/tex; mode=display">\Sigma_{d=1}^nd^2\ \Sigma_{D=1}^{n/d}\mu(D)\lfloor \frac{n}{Dd}\rfloor^2</script><p>设$T=Dd$,得到 </p>
<script type="math/tex; mode=display">\Sigma_{T=1}^{n}\Sigma_{d|T}\ d^2\mu(T/d)\ \lfloor \frac{n}{Dd}\rfloor^2</script><p>中间那个是$id^2$和$\mu$的迪利克雷卷积 </p>
<script type="math/tex; mode=display">\Sigma_{T=1}^{n}\ id^2*\mu\ \lfloor \frac{n}{Dd}\rfloor^2</script><p>假设已经知道中间那个卷积的前缀和,那我们就可以 $O(n^{1/2})$求出答案。 其中$id$,$\mu$都是积性函数,所以中间那个是积性函数,所以可以用线性筛筛出前$1e7$的答案,后面的套用一下杜教筛的公式: </p>
<script type="math/tex; mode=display">g(1)S(n)=\Sigma f*g-\Sigma_{i=2}^{n}g(i)S(\lfloor \frac{n}{i} \rfloor)</script><p>取$g=I_1$就可以了好像,这个时候 </p>
<script type="math/tex; mode=display">f*g(n)=\Sigma_{d|n}d^2*\mu*I_1</script><script type="math/tex; mode=display">f*g(n)=\Sigma_{d|n}d^2*e=id^2</script><p>就没了……注意取模……</p>
<h2 id="代码:"><a href="#代码:" class="headerlink" title="代码:"></a><strong>代码:</strong></h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> db double</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> all(x) x.begin(), x.end()</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SZ(x) (int)(x.size())</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mem(x, y) memset(x, y, sizeof(x))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> what_is(x) cerr << <span class="meta-string">"Line "</span> << __LINE__ << <span class="meta-string">": "</span> << #x << <span class="meta-string">" is "</span> << (x) << endl;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> suf_zero(x) __builtin_ffs(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pre_zero(x) __builtin_clz(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> num_one(x) __builtin_popcount(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> <span class="meta-keyword">error</span>(args...) { string _s = #args; replace(_s.begin(), _s.end(), <span class="meta-string">','</span>, <span class="meta-string">' '</span>); stringstream _ss(_s); istream_iterator<span class="meta-string"><string> _it(_ss); err(_it, args); }</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mt make_tuple</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> eb emplace_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFI 2000000009</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFLL (ll)1e18+7</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ig ignore</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TP tuple<span class="meta-string"><int, int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> lson l, mid, rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rson mid+1, r, rt<<1|1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string"><int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it)</span> </span>{<span class="built_in">cerr</span><<<span class="built_in">endl</span>;}</span><br><span class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it, T a, Args... args)</span> </span>{</span><br><span class="line"> <span class="built_in">cerr</span> << *it << <span class="string">" = "</span> << a << <span class="string">" , "</span>;</span><br><span class="line"> err(++it, args...);</span><br><span class="line">}<span class="comment">// fast IO</span></span><br><span class="line"><span class="keyword">namespace</span> fastIO</span><br><span class="line">{</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">define</span> BUF_SIZE 100000</span></span><br><span class="line"><span class="comment">// fread -> read</span></span><br><span class="line"> <span class="keyword">bool</span> IOerror = <span class="number">0</span>;</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">char</span> <span class="title">nc</span><span class="params">()</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">char</span> buf[BUF_SIZE], *p1 = buf+BUF_SIZE,</span><br><span class="line"> *pend = buf+BUF_SIZE;</span><br><span class="line"> <span class="keyword">if</span>(p1==pend){</span><br><span class="line"> p1 = buf;</span><br><span class="line"> pend = buf+fread(buf, <span class="number">1</span>, BUF_SIZE, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">if</span>(pend==p1){</span><br><span class="line"> IOerror = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> *p1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">bool</span> <span class="title">blank</span><span class="params">( <span class="keyword">char</span> ch )</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">return</span> ch==<span class="string">' '</span>||ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>||ch==<span class="string">'\t'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(<span class="keyword">int</span> &x)</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">char</span> ch;</span><br><span class="line"> <span class="keyword">while</span>(blank(ch=nc()));</span><br><span class="line"> <span class="keyword">if</span>(IOerror)</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">for</span>(x=ch-<span class="string">'0'</span>;(ch=nc())>=<span class="string">'0'</span>&&ch<=<span class="string">'9'</span>;x=x*<span class="number">10</span>+ch-<span class="string">'0'</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">undef</span> BUF_SIZE</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> fastIO;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> PI = <span class="built_in">acos</span>(<span class="number">-1.0</span>);</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">1e-8</span>;</span><br><span class="line"><span class="comment">///////// Macro ////////////////</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">6e6</span>+<span class="number">8</span>;</span><br><span class="line"><span class="keyword">const</span> ll mod = <span class="number">998244353</span>;</span><br><span class="line"><span class="keyword">int</span> isp[maxn+<span class="number">6</span>], p[maxn+<span class="number">5</span>], f[maxn+<span class="number">5</span>], low[maxn+<span class="number">5</span>];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> f[<span class="number">1</span>]=low[<span class="number">1</span>]=<span class="number">1</span>;<span class="keyword">int</span> tot=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<=maxn;++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(!isp[i]) {p[tot++] = i; f[i] = (<span class="number">1L</span>L*i*i<span class="number">-1</span>)%mod; low[i]=i;}</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<tot&&<span class="number">1L</span>L*i*p[j]<=maxn;++j)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> tmp = p[j]*i;</span><br><span class="line"> isp[tmp] = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(i%p[j]==<span class="number">0</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(low[i]==i) f[tmp] = <span class="number">1L</span>L*f[i]*p[j]%mod*p[j]%mod, low[tmp]=low[i]*p[j];</span><br><span class="line"> <span class="keyword">else</span> f[tmp] = <span class="number">1L</span>L*f[i/low[i]]*f[low[i]*p[j]]%mod, low[tmp] = low[i]*p[j];</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> f[tmp] = <span class="number">1L</span>L*f[i] * f[p[j]]%mod;</span><br><span class="line"> low[tmp] = p[j];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<=maxn;++i) f[i]+=f[i<span class="number">-1</span>], f[i]%=mod;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">const</span> ll inv = ((mod+<span class="number">1</span>)/<span class="number">2</span>)*((mod+<span class="number">1</span>)/<span class="number">3</span>)%mod;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><ext/pb_ds/assoc_container.hpp></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><ext/pb_ds/hash_policy.hpp></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> __gnu_pbds;</span><br><span class="line">cc_hash_table<ll, ll> S1;</span><br><span class="line"><span class="function">ll <span class="title">sum</span><span class="params">(ll n)</span></span>{n%=mod;<span class="keyword">return</span> n*(n+<span class="number">1</span>)%mod*(<span class="number">2</span>*n+<span class="number">1</span>)%mod*inv%mod;}</span><br><span class="line"><span class="function">ll <span class="title">M1</span><span class="params">(ll n)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(n<=maxn) <span class="keyword">return</span> f[n];</span><br><span class="line"> <span class="keyword">if</span>(S1[n]) <span class="keyword">return</span> S1[n];</span><br><span class="line"> ll res = sum(n);</span><br><span class="line"> <span class="keyword">for</span>(ll L=<span class="number">2</span>, R;L<=n;L=R+<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> R = n/(n/L);</span><br><span class="line"> res -= (R-L+<span class="number">1</span>)*M1(n/L)%mod;</span><br><span class="line"> res %= mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> S1[n] = (res+mod)%mod;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> aoaoao</span></span><br><span class="line"><span class="comment">// freopen("in.txt", "r", stdin);</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span> <span class="comment">// aoaoao</span></span></span><br><span class="line"> init();</span><br><span class="line"> <span class="keyword">int</span> t;<span class="built_in">scanf</span>(<span class="string">"%d"</span>, &t);</span><br><span class="line"> <span class="keyword">while</span>(t--)</span><br><span class="line"> {</span><br><span class="line"> ll res = <span class="number">0</span>;</span><br><span class="line"> ll n;<span class="built_in">scanf</span>(<span class="string">"%lld"</span>, &n);</span><br><span class="line"> <span class="keyword">for</span>(ll L=<span class="number">1</span>, R;L<=n;L=R+<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> R = n/(n/L);</span><br><span class="line"> ll tmp = n/L;</span><br><span class="line"> res = (res+(M1(R)-M1(L<span class="number">-1</span>))%mod*tmp%mod*tmp%mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span> << (res+mod)%mod << <span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://aoudad.cn/2019/02/18/Camp-Day8-G-穗乃果的考试/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="嗷嗷嗷">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="嗷嗷嗷's Blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/18/Camp-Day8-G-穗乃果的考试/" itemprop="url">Camp Day8 G 穗乃果的考试</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-18T00:08:33+08:00">
2019-02-18
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Camp-day8/" itemprop="url" rel="index">
<span itemprop="name">Camp day8</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body han-init-context" itemprop="articleBody">
<h2 id="题意描述"><a href="#题意描述" class="headerlink" title="题意描述"></a><strong>题意描述</strong></h2><p>为了能在新学期获得$LoveLive!$ 的出场资格,$\mu′s$ 的成员们必须所有考试都要及格才能继续活动。但高坂穗乃果的数学不太好,需要大家的帮助才能及格。<br>有一天,穗乃果碰到了一个这样的数学题,她不太会做,但是如果说自己不会做很可能会被希给予<code>严厉的惩罚</code>,所以她在 $\mu′s$ 粉丝群中找到了学霸的你,希望能请你帮帮她。题目是这样的:<br>给定一个 $n\times m$ 的 $01$ 矩阵,记 $f_i$ 为恰有 $i$ 个 $1$ 的子矩阵的个数,求:$\sum_{i=0}^{nm}i^2 \cdot f_i$<br>输出答案对 $998244353$ 取模的结果。</p>
<h2 id="Input"><a href="#Input" class="headerlink" title="Input"></a><strong>Input</strong></h2><p>第一行两个正整数 $n,m$($1\le n,m \le 2000$),表示矩阵的大小。<br>接下来 $n$ 行,每行$m$个为$0$或为$1$的字符。第$i$行的第$j$个字符代表矩阵的第$i$行的第$j$个元素的值。</p>
<h2 id="Output"><a href="#Output" class="headerlink" title="Output"></a><strong>Output</strong></h2><p>仅一行一个非负整数表示答案对 998244353 取模的结果。</p>
<h2 id="Sample-Input"><a href="#Sample-Input" class="headerlink" title="Sample Input"></a><strong>Sample Input</strong></h2><p>3 3<br>010<br>111<br>010</p>
<h2 id="Sample-Output"><a href="#Sample-Output" class="headerlink" title="Sample Output"></a><strong>Sample Output</strong></h2><p>176</p>
<h2 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a><strong>思路:</strong></h2><p>所求的东西就是对每个子矩阵,设该矩阵的权值为这个矩阵内的$1$的个数的平方,设$sum_{ij}$表示二位前缀和,那么答案就是<script type="math/tex">\Sigma_{i=1}^n\ \Sigma_{j=1}^m\ \Sigma_{k=0}^{i-1}\ \Sigma_{t=0}^{j-1}(sum_{ij}+sum_{kt}-sum_{it}-sum_{kj})^2</script>拆出来分别算一下贡献就好了,复杂度$O(nm)$。感觉有点神奇的。</p>
<h2 id="代码:"><a href="#代码:" class="headerlink" title="代码:"></a><strong>代码:</strong></h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> db double</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> all(x) x.begin(), x.end()</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SZ(x) (int)(x.size())</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mem(x, y) memset(x, y, sizeof(x))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> what_is(x) cerr << <span class="meta-string">"Line "</span> << __LINE__ << <span class="meta-string">": "</span> << #x << <span class="meta-string">" is "</span> << (x) << endl;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> suf_zero(x) __builtin_ffs(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pre_zero(x) __builtin_clz(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> num_one(x) __builtin_popcount(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> <span class="meta-keyword">error</span>(args...) { string _s = #args; replace(_s.begin(), _s.end(), <span class="meta-string">','</span>, <span class="meta-string">' '</span>); stringstream _ss(_s); istream_iterator<span class="meta-string"><string> _it(_ss); err(_it, args); }</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mt make_tuple</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> eb emplace_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFI 2000000009</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFLL (ll)1e18+7</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ig ignore</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TP tuple<span class="meta-string"><int, int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> lson l, mid, rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rson mid+1, r, rt<<1|1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string"><int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it)</span> </span>{<span class="built_in">cerr</span><<<span class="built_in">endl</span>;}</span><br><span class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it, T a, Args... args)</span> </span>{</span><br><span class="line"> <span class="built_in">cerr</span> << *it << <span class="string">" = "</span> << a << <span class="string">" , "</span>;</span><br><span class="line"> err(++it, args...);</span><br><span class="line">}<span class="comment">// fast IO</span></span><br><span class="line"><span class="keyword">namespace</span> fastIO</span><br><span class="line">{</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">define</span> BUF_SIZE 100000</span></span><br><span class="line"><span class="comment">// fread -> read</span></span><br><span class="line"> <span class="keyword">bool</span> IOerror = <span class="number">0</span>;</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">char</span> <span class="title">nc</span><span class="params">()</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">char</span> buf[BUF_SIZE], *p1 = buf+BUF_SIZE,</span><br><span class="line"> *pend = buf+BUF_SIZE;</span><br><span class="line"> <span class="keyword">if</span>(p1==pend){</span><br><span class="line"> p1 = buf;</span><br><span class="line"> pend = buf+fread(buf, <span class="number">1</span>, BUF_SIZE, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">if</span>(pend==p1){</span><br><span class="line"> IOerror = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> *p1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">bool</span> <span class="title">blank</span><span class="params">( <span class="keyword">char</span> ch )</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">return</span> ch==<span class="string">' '</span>||ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>||ch==<span class="string">'\t'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(<span class="keyword">int</span> &x)</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">char</span> ch;</span><br><span class="line"> <span class="keyword">while</span>(blank(ch=nc()));</span><br><span class="line"> <span class="keyword">if</span>(IOerror)</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">for</span>(x=ch-<span class="string">'0'</span>;(ch=nc())>=<span class="string">'0'</span>&&ch<=<span class="string">'9'</span>;x=x*<span class="number">10</span>+ch-<span class="string">'0'</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">undef</span> BUF_SIZE</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> fastIO;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> PI = <span class="built_in">acos</span>(<span class="number">-1.0</span>);</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">1e-8</span>;</span><br><span class="line"><span class="comment">///////// Macro ////////////////</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">2e3</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">char</span> s[maxn];</span><br><span class="line"><span class="keyword">const</span> ll mod = <span class="number">998244353</span>;</span><br><span class="line">ll a[maxn][maxn], sum[maxn][maxn];</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">g</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> X, <span class="keyword">int</span> y, <span class="keyword">int</span> Y)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(X<=<span class="number">0</span>||y<=<span class="number">0</span>) <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">return</span> (sum[X][Y]-sum[X][y<span class="number">-1</span>]-sum[x<span class="number">-1</span>][Y]+sum[x<span class="number">-1</span>][y<span class="number">-1</span>]+mod+mod)%mod;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> n, m;</span><br><span class="line"> <span class="built_in">cin</span> >> n >> m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%s"</span>, s+<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;++j)</span><br><span class="line"> a[i][j] = s[j]-<span class="string">'0'</span>;</span><br><span class="line"> }</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)a[i][j]+=a[i][j<span class="number">-1</span>], a[i][j]%=mod;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)a[i][j]+=a[i<span class="number">-1</span>][j], a[i][j]%=mod;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)sum[i][j]=a[i][j];</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)sum[i][j]+=sum[i][j<span class="number">-1</span>], sum[i][j]%=mod;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)sum[i][j]+=sum[i<span class="number">-1</span>][j], sum[i][j]%=mod;</span><br><span class="line"> ll res = <span class="number">0</span>;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> ll s = a[i][j]*a[i][j]%mod;</span><br><span class="line"> res = (res+s*i%mod*j%mod)%mod;</span><br><span class="line"> res = (res+s*i%mod*(m-j)%mod)%mod;</span><br><span class="line"> res = (res+s*(n-i)%mod*(m-j)%mod)%mod;</span><br><span class="line"> res = (res+s*(n-i)%mod*j%mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>) res = (res+<span class="number">2</span>*a[i][j]*g(<span class="number">1</span>, i<span class="number">-1</span>, <span class="number">1</span>, j<span class="number">-1</span>))%mod;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">0</span>, m) res = (res+<span class="number">2</span>*a[i][j]*g(<span class="number">1</span>, i<span class="number">-1</span>, j+<span class="number">1</span>, m))%mod;</span><br><span class="line"> ll tmp = <span class="number">0</span>;</span><br><span class="line"> rep(i, <span class="number">1</span>, n+<span class="number">1</span>) rep(j, <span class="number">1</span>, m+<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> tmp = (tmp+a[i][j]*i*<span class="number">2</span>%mod*g(i, i, <span class="number">1</span>, j<span class="number">-1</span>)%mod)%mod;</span><br><span class="line"> tmp = (tmp+a[i][j]*j*<span class="number">2</span>%mod*g(<span class="number">1</span>, i<span class="number">-1</span>, j, j)%mod)%mod;</span><br><span class="line"> tmp = (tmp+<span class="number">2</span>*(m-j+<span class="number">1</span>)*a[i][j<span class="number">-1</span>]%mod*g(<span class="number">1</span>, i<span class="number">-1</span>, j<span class="number">-1</span>, j<span class="number">-1</span>)%mod)%mod;</span><br><span class="line"> tmp = (tmp+<span class="number">2</span>*(n-i+<span class="number">1</span>)*a[i<span class="number">-1</span>][j]%mod*g(i<span class="number">-1</span>, i<span class="number">-1</span>, <span class="number">1</span>, j<span class="number">-1</span>)%mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span> << (res-tmp+mod)%mod << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://aoudad.cn/2019/02/17/Camp-Day5-I-Sorting/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="嗷嗷嗷">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="嗷嗷嗷's Blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/17/Camp-Day5-I-Sorting/" itemprop="url">Camp Day5 I Sorting</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-17T21:49:21+08:00">
2019-02-17
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Camp-day5/" itemprop="url" rel="index">
<span itemprop="name">Camp day5</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body han-init-context" itemprop="articleBody">
<h2 id="题意描述"><a href="#题意描述" class="headerlink" title="题意描述"></a><strong>题意描述</strong></h2><p>你有一个数列$a_1, a_2, \dots, a_$,你要模拟一个类似于快速排序的过程。有一个固定的数字$x$。<br>你要支持三种操作:</p>
<ul>
<li>询问区间$[l, r]$之间的元素的和,也就是$\sum_{i=l}^r a_i$。</li>
<li>对区间$[l,r]$进行操作,也就是说你把区间中所有的数字拿出来,然后把小于等于$x$的数字按顺序放在左边,把大于$x$的数字按顺序放在右边,把这些数字接起来,放回到数列中。比如说$x=3$,你的区间里的数字是$1,5,3,2,4$,那么操作完之后区间里面的数字变为$1,3,2,5,4$。</li>
<li>对区间$[l,r]$进行操作,也就是说你把区间中所有的数字拿出来,然后把大于$x$的数字按顺序放在左边,把小于等于$x$的数字按顺序放在右边,把这些数字接起来,放回到数列中。</li>
</ul>
<h2 id="Input"><a href="#Input" class="headerlink" title="Input"></a><strong>Input</strong></h2><p>第一行三个整数$n, q, x$ ( $1\leq n, q \leq 2*10^5, 0\leq x\leq 10^9)$表示元素的个数和询问的个数。<br>接下来一行$n$个整数$a_1, a_2, \dots, a_n(1\leq a_i\leq 10^9)$。<br>接下来$q$行,每行三个正整数$p, l, r (1\leq p\leq 3), 1\leq l\leq r\leq n$表示操作种类和区间。</p>
<h2 id="Output"><a href="#Output" class="headerlink" title="Output"></a><strong>Output</strong></h2><p>对于每个第一种操作,输出一行,表示答案。</p>
<h2 id="Sample-Input"><a href="#Sample-Input" class="headerlink" title="Sample Input"></a><strong>Sample Input</strong></h2><p>5 9 3<br>1 5 3 2 4<br>1 1 5<br>2 1 5<br>1 1 1<br>1 2 2<br>1 3 3<br>1 4 4<br>1 5 5<br>3 3 5<br>1 1 4</p>
<h2 id="Sample-Output"><a href="#Sample-Output" class="headerlink" title="Sample Output"></a><strong>Sample Output</strong></h2><p>15<br>1<br>3<br>2<br>5<br>4<br>13</p>
<h2 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a><strong>思路:</strong></h2><p>进行操作二的时候,小于等于$x$的数和大于$x$的数各自之间的相对顺序是不变的。分别用$0$和$1$标记$a[i]$,$0$表示这个数小于等于$x$,那么操作二就是将当前区间中的所有$0$移到左半部分,$1$移到右半部分,操作三相反,询问$1$只需要知道在当前区间内的是哪几个$0$哪几个$1$就行了,所以用个线段树维护一下区间和就可以了。另外分别提前处理一下前缀和,复杂度$O(q\log n)$。</p>
<h2 id="代码:"><a href="#代码:" class="headerlink" title="代码:"></a><strong>代码:</strong></h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> db double</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> all(x) x.begin(), x.end()</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SZ(x) (int)(x.size())</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mem(x, y) memset(x, y, sizeof(x))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> what_is(x) cerr << <span class="meta-string">"Line "</span> << __LINE__ << <span class="meta-string">": "</span> << #x << <span class="meta-string">" is "</span> << (x) << endl;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> suf_zero(x) __builtin_ffs(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pre_zero(x) __builtin_clz(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> num_one(x) __builtin_popcount(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> <span class="meta-keyword">error</span>(args...) { string _s = #args; replace(_s.begin(), _s.end(), <span class="meta-string">','</span>, <span class="meta-string">' '</span>); stringstream _ss(_s); istream_iterator<span class="meta-string"><string> _it(_ss); err(_it, args); }</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mt make_tuple</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> eb emplace_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFI 2000000009</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFLL (ll)1e18+7</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ig ignore</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TP tuple<span class="meta-string"><int, int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> lson l, mid, rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rson mid+1, r, rt<<1|1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string"><int, int></span></span></span><br><span class="line"><span class="comment">//#define rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it)</span> </span>{<span class="built_in">cerr</span><<<span class="built_in">endl</span>;}</span><br><span class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it, T a, Args... args)</span> </span>{</span><br><span class="line"> <span class="built_in">cerr</span> << *it << <span class="string">" = "</span> << a << <span class="string">" , "</span>;</span><br><span class="line"> err(++it, args...);</span><br><span class="line">}<span class="comment">// fast IO</span></span><br><span class="line"><span class="keyword">namespace</span> fastIO</span><br><span class="line">{</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">define</span> BUF_SIZE 100000</span></span><br><span class="line"><span class="comment">// fread -> read</span></span><br><span class="line"> <span class="keyword">bool</span> IOerror = <span class="number">0</span>;</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">char</span> <span class="title">nc</span><span class="params">()</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">char</span> buf[BUF_SIZE], *p1 = buf+BUF_SIZE,</span><br><span class="line"> *pend = buf+BUF_SIZE;</span><br><span class="line"> <span class="keyword">if</span>(p1==pend){</span><br><span class="line"> p1 = buf;</span><br><span class="line"> pend = buf+fread(buf, <span class="number">1</span>, BUF_SIZE, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">if</span>(pend==p1){</span><br><span class="line"> IOerror = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> *p1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">bool</span> <span class="title">blank</span><span class="params">( <span class="keyword">char</span> ch )</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">return</span> ch==<span class="string">' '</span>||ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>||ch==<span class="string">'\t'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(<span class="keyword">int</span> &x)</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">char</span> ch;</span><br><span class="line"> <span class="keyword">while</span>(blank(ch=nc()));</span><br><span class="line"> <span class="keyword">if</span>(IOerror)</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">for</span>(x=ch-<span class="string">'0'</span>;(ch=nc())>=<span class="string">'0'</span>&&ch<=<span class="string">'9'</span>;x=x*<span class="number">10</span>+ch-<span class="string">'0'</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">undef</span> BUF_SIZE</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> fastIO;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> PI = <span class="built_in">acos</span>(<span class="number">-1.0</span>);</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">1e-8</span>;</span><br><span class="line"><span class="comment">///////// Macro ////////////////</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">4e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">int</span> sum[maxn<<<span class="number">2</span>], st[maxn<<<span class="number">2</span>];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pushup</span><span class="params">(<span class="keyword">int</span> rt)</span></span>{sum[rt]=sum[rt<<<span class="number">1</span>]+sum[rt<<<span class="number">1</span>|<span class="number">1</span>];}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pushdown</span><span class="params">(<span class="keyword">int</span> rt, <span class="keyword">int</span> len)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(st[rt]==<span class="number">-1</span>)<span class="keyword">return</span>;</span><br><span class="line"> st[rt<<<span class="number">1</span>]=st[rt<<<span class="number">1</span>|<span class="number">1</span>]=st[rt];</span><br><span class="line"> sum[rt<<<span class="number">1</span>] = st[rt]*(len-len/<span class="number">2</span>);</span><br><span class="line"> sum[rt<<<span class="number">1</span>|<span class="number">1</span>] = st[rt] * (len/<span class="number">2</span>);</span><br><span class="line"> st[rt]=<span class="number">-1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">int</span> a[maxn], x;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">build</span><span class="params">(<span class="keyword">int</span> l, <span class="keyword">int</span> r, <span class="keyword">int</span> rt)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> st[rt]=<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">if</span>(l==r){sum[rt]=a[l]>x;<span class="keyword">return</span> ;}</span><br><span class="line"> <span class="keyword">int</span> mid = (l+r)>><span class="number">1</span>;</span><br><span class="line"> build(lson);build(rson);</span><br><span class="line"> pushup(rt);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">query</span><span class="params">(<span class="keyword">int</span> L, <span class="keyword">int</span> R, <span class="keyword">int</span> l, <span class="keyword">int</span> r, <span class="keyword">int</span> rt)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(L<=l&&r<=R){<span class="keyword">return</span> sum[rt];}</span><br><span class="line"> <span class="keyword">int</span> mid = (l+r)>><span class="number">1</span>, res=<span class="number">0</span>;</span><br><span class="line"> pushdown(rt, r-l+<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">if</span>(L<=mid) res = query(L, R, lson);</span><br><span class="line"> <span class="keyword">if</span>(mid<R) res+=query(L, R, rson);</span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">update</span><span class="params">(<span class="keyword">int</span> L, <span class="keyword">int</span> R, <span class="keyword">int</span> x, <span class="keyword">int</span> l, <span class="keyword">int</span> r, <span class="keyword">int</span> rt)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(L<=l&&r<=R){st[rt]=x;sum[rt]=x*(r-l+<span class="number">1</span>);<span class="keyword">return</span> ;}</span><br><span class="line"> <span class="keyword">int</span> mid = (l+r)>><span class="number">1</span>;pushdown(rt, r-l+<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">if</span>(L<=mid) update(L, R, x, lson);</span><br><span class="line"> <span class="keyword">if</span>(mid<R) update(L, R, x, rson);</span><br><span class="line"> pushup(rt);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> n, m;</span><br><span class="line"> <span class="built_in">cin</span> >> n >> m >> x;<span class="built_in">vector</span><ll> res[<span class="number">2</span>];res[<span class="number">0</span>].eb(<span class="number">0</span>), res[<span class="number">1</span>].eb(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i){<span class="built_in">scanf</span>(<span class="string">"%d"</span>, a+i);res[a[i]>x].eb(a[i]);}</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<res[<span class="number">0</span>].size();++i) res[<span class="number">0</span>][i]+=res[<span class="number">0</span>][i<span class="number">-1</span>];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<res[<span class="number">1</span>].size();++i) res[<span class="number">1</span>][i]+=res[<span class="number">1</span>][i<span class="number">-1</span>];</span><br><span class="line"> build(<span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<m;++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> opt, x, y;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d"</span>, &opt, &x, &y);</span><br><span class="line"> <span class="keyword">if</span>(opt==<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> pre = <span class="number">0</span>, now = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(x><span class="number">1</span>) pre = query(<span class="number">1</span>, x<span class="number">-1</span>, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> now = query(x, y, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> ll ans = <span class="number">0</span>;</span><br><span class="line"> ans += res[<span class="number">1</span>][pre+now] - res[<span class="number">1</span>][pre];</span><br><span class="line"> ans += res[<span class="number">0</span>][y-pre-now] - res[<span class="number">0</span>][x<span class="number">-1</span>-pre];</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>, ans);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(opt==<span class="number">2</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> one = query(x, y, <span class="number">1</span>, n, <span class="number">1</span>), zero = y-x+<span class="number">1</span>-one;</span><br><span class="line"> update(x, x+zero<span class="number">-1</span>, <span class="number">0</span>, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> update(x+zero, y, <span class="number">1</span>, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(opt==<span class="number">3</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> one = query(x, y, <span class="number">1</span>, n, <span class="number">1</span>), zero = y-x+<span class="number">1</span>-one;</span><br><span class="line"> update(x, x+one<span class="number">-1</span>, <span class="number">1</span>, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"> update(x+one, y, <span class="number">0</span>, <span class="number">1</span>, n, <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://aoudad.cn/2019/02/17/Camp-Day5-E-Fast-Kronecker-Transform/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="嗷嗷嗷">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="嗷嗷嗷's Blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/17/Camp-Day5-E-Fast-Kronecker-Transform/" itemprop="url">Camp Day5 E Fast Kronecker Transform</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-17T21:08:27+08:00">
2019-02-17
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Camp-day5/" itemprop="url" rel="index">
<span itemprop="name">Camp day5</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body han-init-context" itemprop="articleBody">
<h2 id="题意描述"><a href="#题意描述" class="headerlink" title="题意描述"></a><strong>题意描述</strong></h2><p>给你两个数列$a_0, a_1, \dots, a_n$,$b_0, b_1, \dots, b_m$。<br>求一个数列$c_k$ ($0\leq k\leq n+m$),其中$c_k=(\sum_{i+j=k} ij\delta_{a_i, b_j}) \bmod 998244353$,其中$\delta_{a,b}$为$Kronecker$符号,当$a=b$是$\delta_{a,b}=1$,否则为$0$。</p>
<h2 id="Input"><a href="#Input" class="headerlink" title="Input"></a><strong>Input</strong></h2><p>第一行输入两个整数$n,m$ ($1\leq n,m\leq 10^5$)。<br>接下来一行$n+1$个整数$a_0, a_1, \dots, a_n$,接下来一行$m+1$个整数$b_0, b_1, \dots, b_m$ ($1\leq a_i,b_i\leq 10^9$)。</p>
<h2 id="Output"><a href="#Output" class="headerlink" title="Output"></a><strong>Output</strong></h2><p>输出$n+m+1$个整数,表示$c_0, c_1, \dots, c_{n+m}$。</p>
<p><strong>Sample Input</strong><br>—-5 5<br>1 2 1 3 2 2<br>3 1 2 3 1 2</p>
<h2 id="Sample-Output"><a href="#Sample-Output" class="headerlink" title="Sample Output"></a><strong>Sample Output</strong></h2><p>0 0 0 4 0 0 30 10 0 20 25</p>
<h2 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a><strong>思路:</strong></h2><p>枚举每个数,拎出来做卷积,当该数的出现次数较少时(我是上面的数量乘下面的数量小于1e7时),直接暴力比较快,不然就做 $NTT$ 。注意爆 $int$ 和离散化……</p>
<h2 id="代码:"><a href="#代码:" class="headerlink" title="代码:"></a><strong>代码:</strong></h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> db double</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> all(x) x.begin(), x.end()</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> SZ(x) (int)(x.size())</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mem(x, y) memset(x, y, sizeof(x))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> what_is(x) cerr << <span class="meta-string">"Line "</span> << __LINE__ << <span class="meta-string">": "</span> << #x << <span class="meta-string">" is "</span> << (x) << endl;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> suf_zero(x) __builtin_ffs(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pre_zero(x) __builtin_clz(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> num_one(x) __builtin_popcount(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> <span class="meta-keyword">error</span>(args...) { string _s = #args; replace(_s.begin(), _s.end(), <span class="meta-string">','</span>, <span class="meta-string">' '</span>); stringstream _ss(_s); istream_iterator<span class="meta-string"><string> _it(_ss); err(_it, args); }</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mt make_tuple</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> eb emplace_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFI 2000000009</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFLL (ll)1e18+7</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ig ignore</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TP tuple<span class="meta-string"><int, int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> lson l, m, rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rson m+1, r, rt<<1|1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string"><int, int></span></span></span><br><span class="line"><span class="comment">//#define rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it)</span> </span>{<span class="built_in">cerr</span><<<span class="built_in">endl</span>;}</span><br><span class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it, T a, Args... args)</span> </span>{</span><br><span class="line"> <span class="built_in">cerr</span> << *it << <span class="string">" = "</span> << a << <span class="string">" , "</span>;</span><br><span class="line"> err(++it, args...);</span><br><span class="line">}<span class="comment">// fast IO</span></span><br><span class="line"><span class="keyword">namespace</span> fastIO</span><br><span class="line">{</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">define</span> BUF_SIZE 100000</span></span><br><span class="line"><span class="comment">// fread -> read</span></span><br><span class="line"> <span class="keyword">bool</span> IOerror = <span class="number">0</span>;</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">char</span> <span class="title">nc</span><span class="params">()</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">char</span> buf[BUF_SIZE], *p1 = buf+BUF_SIZE,</span><br><span class="line"> *pend = buf+BUF_SIZE;</span><br><span class="line"> <span class="keyword">if</span>(p1==pend){</span><br><span class="line"> p1 = buf;</span><br><span class="line"> pend = buf+fread(buf, <span class="number">1</span>, BUF_SIZE, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">if</span>(pend==p1){</span><br><span class="line"> IOerror = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> *p1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">bool</span> <span class="title">blank</span><span class="params">( <span class="keyword">char</span> ch )</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">return</span> ch==<span class="string">' '</span>||ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>||ch==<span class="string">'\t'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(<span class="keyword">int</span> &x)</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">char</span> ch;</span><br><span class="line"> <span class="keyword">while</span>(blank(ch=nc()));</span><br><span class="line"> <span class="keyword">if</span>(IOerror)</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">for</span>(x=ch-<span class="string">'0'</span>;(ch=nc())>=<span class="string">'0'</span>&&ch<=<span class="string">'9'</span>;x=x*<span class="number">10</span>+ch-<span class="string">'0'</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">undef</span> BUF_SIZE</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> fastIO;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> PI = <span class="built_in">acos</span>(<span class="number">-1.0</span>);</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">1e-8</span>;</span><br><span class="line"><span class="comment">///////// Macro ////////////////</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">4e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">const</span> ll mod = <span class="number">998244353</span>;</span><br><span class="line"><span class="keyword">const</span> ll g = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">int</span> rev[maxn];</span><br><span class="line"><span class="function">ll <span class="title">qp</span><span class="params">(ll b, ll n)</span></span>{ll r=<span class="number">1</span>;<span class="keyword">for</span>(;n;b=b*b%mod,n>>=<span class="number">1</span>)<span class="keyword">if</span>(n&<span class="number">1</span>)r=r*b%mod;<span class="keyword">return</span> r;}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">NTT</span><span class="params">(ll x[], <span class="keyword">int</span> len, <span class="keyword">int</span> on)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> bit=suf_zero(len)<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<len;++i) rev[i] = ((rev[i>><span class="number">1</span>]>><span class="number">1</span>)|((i&<span class="number">1</span>)<<(bit<span class="number">-1</span>)));</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<len;++i) <span class="keyword">if</span>(i<rev[i]) swap(x[i], x[rev[i]]);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> h=<span class="number">2</span>;h<=len;h<<=<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> ll wn = qp(g, (mod<span class="number">-1</span>)/h);</span><br><span class="line"> <span class="keyword">if</span>(on==<span class="number">-1</span>) wn=qp(wn, mod<span class="number">-2</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<len;j+=h)</span><br><span class="line"> {</span><br><span class="line"> ll w = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=j;k<j+h/<span class="number">2</span>;++k)</span><br><span class="line"> {</span><br><span class="line"> ll u = x[k], t = w*x[k+h/<span class="number">2</span>]%mod;</span><br><span class="line"> x[k] = (u+t)%mod;</span><br><span class="line"> x[k+h/<span class="number">2</span>] = (u-t+mod)%mod;</span><br><span class="line"> w = w*wn%mod;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(on==<span class="number">-1</span>){ll t=qp(len, mod<span class="number">-2</span>);<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<len;++i)x[i]=x[i]*t%mod;}</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">calc</span><span class="params">(ll x[], ll y[], <span class="keyword">int</span> len)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> NTT(x, len, <span class="number">1</span>);NTT(y, len, <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<len;++i) x[i]=x[i]*y[i]%mod;</span><br><span class="line"> NTT(x, len, <span class="number">-1</span>);</span><br><span class="line">}</span><br><span class="line">ll x[maxn], y[maxn];</span><br><span class="line"><span class="keyword">int</span> head[<span class="number">2</span>][maxn], nxt[<span class="number">2</span>][maxn], sz[<span class="number">2</span>][maxn];</span><br><span class="line">ll resx[maxn], resy[maxn];</span><br><span class="line">ll res[maxn];</span><br><span class="line"><span class="keyword">const</span> ll LIMIT = <span class="number">1e7</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> n, m;<span class="built_in">cin</span> >> n >> m;</span><br><span class="line"> mem(head, <span class="number">-1</span>);mem(nxt, <span class="number">-1</span>);<span class="built_in">vector</span><ll> MP;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=n;++i) <span class="built_in">scanf</span>(<span class="string">"%lld"</span>, x+i), MP.eb(x[i]);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=m;++i) <span class="built_in">scanf</span>(<span class="string">"%lld"</span>, y+i), MP.eb(y[i]);</span><br><span class="line"> sort(all(MP));MP.erase(unique(all(MP)), MP.end());</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=n;++i)</span><br><span class="line"> {</span><br><span class="line"> x[i] = lower_bound(all(MP), x[i])-MP.begin();</span><br><span class="line"> nxt[<span class="number">0</span>][i] = head[<span class="number">0</span>][x[i]];</span><br><span class="line"> head[<span class="number">0</span>][x[i]] = i;</span><br><span class="line"> ++sz[<span class="number">0</span>][x[i]];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=m;++i)</span><br><span class="line"> {</span><br><span class="line"> y[i] = lower_bound(all(MP), y[i])-MP.begin();</span><br><span class="line"> nxt[<span class="number">1</span>][i] = head[<span class="number">1</span>][y[i]];</span><br><span class="line"> head[<span class="number">1</span>][y[i]] = i;</span><br><span class="line"> ++sz[<span class="number">1</span>][y[i]];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> len=<span class="number">1</span>;<span class="keyword">while</span>(len<n+<span class="number">1</span>+m+<span class="number">1</span>)len<<=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<SZ(MP);++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(sz[<span class="number">0</span>][i]*<span class="number">1L</span>L*sz[<span class="number">1</span>][i]<=LIMIT)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=head[<span class="number">0</span>][i];x!=<span class="number">-1</span>;x=nxt[<span class="number">0</span>][x])</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=head[<span class="number">1</span>][i];y!=<span class="number">-1</span>;y=nxt[<span class="number">1</span>][y])</span><br><span class="line"> {</span><br><span class="line"> res[x+y] += <span class="number">1L</span>L*x*y%mod;</span><br><span class="line"> res[x+y] %= mod;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=head[<span class="number">0</span>][i];x!=<span class="number">-1</span>;x=nxt[<span class="number">0</span>][x]) resx[x] = x;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=head[<span class="number">1</span>][i];y!=<span class="number">-1</span>;y=nxt[<span class="number">1</span>][y]) resy[y] = y;</span><br><span class="line"> calc(resx, resy, len);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<len;++i) res[i]=(res[i]+resx[i])%mod;</span><br><span class="line"> mem(resx,<span class="number">0</span>);mem(resy,<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=n+m;++i)</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld%c"</span>, res[i], <span class="string">" \n"</span>[i==n+m]);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://aoudad.cn/2019/02/16/Camp-Day1-G-双重矩阵/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="嗷嗷嗷">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="嗷嗷嗷's Blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/16/Camp-Day1-G-双重矩阵/" itemprop="url">Camp Day1 G 双重矩阵</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-16T19:28:01+08:00">
2019-02-16
</time>
</span>
<span class="post-category" >
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/Camp-day1/" itemprop="url" rel="index">
<span itemprop="name">Camp day1</span>
</a>
</span>
</span>
</div>
</header>
<div class="post-body han-init-context" itemprop="articleBody">
<h2 id="题意描述"><a href="#题意描述" class="headerlink" title="题意描述"></a><strong>题意描述</strong></h2><p>$wls$有一个 $n$ 行 $m$ 列的矩阵,矩阵中的每个元素都是一个整数。<br>$wls$ 以这个矩阵为基础,构造了一个更大的 $x$ 行 $y$ 列的矩阵,大矩阵中的每个元素都是这个 $n$ 行 $m$ 列的小矩阵。<br>现在 $wls$想知道,在这个大矩阵中,最大公约数不为 $1$ 的最大的子矩阵包含多少个元素?</p>
<h2 id="Input"><a href="#Input" class="headerlink" title="Input"></a><strong>Input</strong></h2><p>第一行四个整数 $n$,$m$,$x$,$y$。<br>接下来 $n$ 行,每行 $m$ 个整数表示矩阵。<br>$1 \leq n, m \leq 100$<br>$1 \leq x, y \leq 1000000$<br>$1 \leq 矩阵元素 \leq 1000000000$</p>
<h2 id="Output"><a href="#Output" class="headerlink" title="Output"></a><strong>Output</strong></h2><p>一行一个整数表示答案。</p>
<h2 id="Sample-Input"><a href="#Sample-Input" class="headerlink" title="Sample Input"></a><strong>Sample Input</strong></h2><p>3 3 2 2<br>2 3 2<br>2 3 2<br>2 3 2</p>
<h2 id="Sample-Output"><a href="#Sample-Output" class="headerlink" title="Sample Output"></a><strong>Sample Output</strong></h2><p>12</p>
<h2 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a><strong>思路:</strong></h2><p>假设$xy$都大于等于$2$,将矩阵横宽翻两倍,结果就是那么就只有四种情况,全都可以,一整行,一整列,还有一个块。所以现在问题就是怎么找一个矩阵里面$gcd$大于$1$的最大子矩阵。先枚举上下界,取$gcd$压成一行,$st$表处理一下,枚举左边界二分右边界,复杂度$O(n^3logn)。$</p>
<h2 id="代码:"><a href="#代码:" class="headerlink" title="代码:"></a><strong>代码:</strong></h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> what_is(x) cerr << <span class="meta-string">"Line "</span> << __LINE__ << <span class="meta-string">": "</span> << #x << <span class="meta-string">" is "</span> << (x) << endl;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> suf_zero(x) __builtin_ffs(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> pre_zero(x) __builtin_clz(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> num_one(x) __builtin_popcount(x)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> <span class="meta-keyword">error</span>(args...) { string _s = #args; replace(_s.begin(), _s.end(), <span class="meta-string">','</span>, <span class="meta-string">' '</span>); stringstream _ss(_s); istream_iterator<span class="meta-string"><string> _it(_ss); err(_it, args); }</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mt make_tuple</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> mp make_pair</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> eb emplace_back</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFI 2000000009</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INFLL (ll)1e18+7</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ig ignore</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fi first</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TP tuple<span class="meta-string"><int, int, int></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> se second</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> lson l, m, rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rson m+1, r, rt<<1|1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PII pair<span class="meta-string"><int, int></span></span></span><br><span class="line"><span class="comment">//#define rep(i, begin, end) for(__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it)</span> </span>{<span class="built_in">cerr</span><<<span class="built_in">endl</span>;}</span><br><span class="line"><span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">err</span><span class="params">(istream_iterator<<span class="built_in">string</span>> it, T a, Args... args)</span> </span>{</span><br><span class="line"> <span class="built_in">cerr</span> << *it << <span class="string">" = "</span> << a << <span class="string">" , "</span>;</span><br><span class="line"> err(++it, args...);</span><br><span class="line">}<span class="comment">// fast IO</span></span><br><span class="line"><span class="keyword">namespace</span> fastIO</span><br><span class="line">{</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">define</span> BUF_SIZE 100000</span></span><br><span class="line"><span class="comment">// fread -> read</span></span><br><span class="line"> <span class="keyword">bool</span> IOerror = <span class="number">0</span>;</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">char</span> <span class="title">nc</span><span class="params">()</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">char</span> buf[BUF_SIZE], *p1 = buf+BUF_SIZE,</span><br><span class="line"> *pend = buf+BUF_SIZE;</span><br><span class="line"> <span class="keyword">if</span>(p1==pend){</span><br><span class="line"> p1 = buf;</span><br><span class="line"> pend = buf+fread(buf, <span class="number">1</span>, BUF_SIZE, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">if</span>(pend==p1){</span><br><span class="line"> IOerror = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> *p1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">bool</span> <span class="title">blank</span><span class="params">( <span class="keyword">char</span> ch )</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">return</span> ch==<span class="string">' '</span>||ch==<span class="string">'\n'</span>||ch==<span class="string">'\r'</span>||ch==<span class="string">'\t'</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="function"><span class="keyword">inline</span> <span class="keyword">void</span> <span class="title">read</span><span class="params">(<span class="keyword">int</span> &x)</span></span></span><br><span class="line"><span class="function"> </span>{</span><br><span class="line"> <span class="keyword">char</span> ch;</span><br><span class="line"> <span class="keyword">while</span>(blank(ch=nc()));</span><br><span class="line"> <span class="keyword">if</span>(IOerror)</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">for</span>(x=ch-<span class="string">'0'</span>;(ch=nc())>=<span class="string">'0'</span>&&ch<=<span class="string">'9'</span>;x=x*<span class="number">10</span>+ch-<span class="string">'0'</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">#<span class="meta-keyword">undef</span> BUF_SIZE</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> fastIO;</span><br><span class="line"></span><br><span class="line"><span class="comment">///////// Macro ////////////////</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">405</span>;</span><br><span class="line"><span class="keyword">int</span> mm[maxn], a[maxn][maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">(<span class="keyword">int</span> n, <span class="keyword">int</span> m)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> mm[<span class="number">0</span>]=<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<maxn;++i) mm[i] = mm[i<span class="number">-1</span>]+((i&(i<span class="number">-1</span>))==<span class="number">0</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">int</span> st[maxn][<span class="number">20</span>], dd[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">binchk</span><span class="params">(<span class="keyword">int</span> i, <span class="keyword">int</span> x)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> t = mm[x-i+<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">return</span> __gcd(st[i][t], st[x-(<span class="number">1</span><<t)+<span class="number">1</span>][t]) > <span class="number">1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">chk</span><span class="params">(<span class="keyword">int</span> m)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;++i) st[i][<span class="number">0</span>] = dd[i];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k<=mm[m];++k)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m-(<span class="number">1</span><<k)+<span class="number">1</span>;++i)</span><br><span class="line"> st[i][k] = __gcd(st[i][k<span class="number">-1</span>], st[i+(<span class="number">1</span><<(k<span class="number">-1</span>))][k<span class="number">-1</span>]);</span><br><span class="line"> <span class="keyword">int</span> tmp = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> L = i, R = m, mid, ans=i<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">while</span>(L<=R)</span><br><span class="line"> {</span><br><span class="line"> mid = (L+R)>><span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(binchk(i, mid)) L = mid + <span class="number">1</span>, ans = mid;</span><br><span class="line"> <span class="keyword">else</span> R = mid - <span class="number">1</span>;</span><br><span class="line"><span class="comment">// error(i, mid);</span></span><br><span class="line"> }</span><br><span class="line"> tmp = max(tmp, ans-i+<span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> tmp;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> n, m, x, y;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d%d"</span>, &n, &m, &x, &y);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;++j){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &a[i][j]);</span><br><span class="line"> a[i+n][j]=a[i][j+m]=a[i+n][j+m]=a[i][j];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> tn = n, tm = m;</span><br><span class="line"> n*=<span class="number">2</span>;m*=<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">if</span>(x==<span class="number">1</span>)n/=<span class="number">2</span>;<span class="keyword">if</span>(y==<span class="number">1</span>)m/=<span class="number">2</span>;</span><br><span class="line"> init(n, m);</span><br><span class="line"> ll ans = <span class="number">0</span>, Lflag=<span class="number">0</span>, Rflag=<span class="number">0</span>, area = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=i;j<=n;++j)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(j==i) <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k<=m;++k) dd[k] = a[i][k];</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k<=m;++k) dd[k] = __gcd(dd[k], a[j][k]);</span><br><span class="line"> ll chkm = chk(m);</span><br><span class="line"> area = max(area, chkm*(j-i+<span class="number">1</span>));</span><br><span class="line"> <span class="keyword">if</span>(j-i+<span class="number">1</span>==n) Lflag = max(Lflag, (ll)chkm);</span><br><span class="line"> <span class="keyword">if</span>(chkm==m) Rflag = max(Rflag, (ll)j-i+<span class="number">1</span>);</span><br><span class="line"><span class="comment">// error(ans, area, chkm, i, j);</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"><span class="comment">// error(Rflag, Lflag, area);</span></span><br><span class="line"> <span class="keyword">if</span>(Rflag*Lflag==n*m) area = <span class="number">1L</span>L*tn*tm*x*y;</span><br><span class="line"> <span class="keyword">if</span>(Rflag) area = max(area, Rflag*tm*y);</span><br><span class="line"> <span class="keyword">if</span>(Lflag) area = max(area, Lflag*tn*x);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>, area);</span><br><span class="line">}</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">2 2 3 4</span></span><br><span class="line"><span class="comment">2 2</span></span><br><span class="line"><span class="comment">2 3</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">3 3 2 2</span></span><br><span class="line"><span class="comment">2 3 2</span></span><br><span class="line"><span class="comment">5 7 9</span></span><br><span class="line"><span class="comment">2 11 2</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>