原创 [ 雜題 ] Codeforces946G Almost Increasing Array

如果不能刪除且不是嚴格遞增,答案就是 n−最長不下降子序列長度n−最長不下降子序列長度 。 假如嚴格遞增,可以將 aiai 減去 ii ,再求一遍 LISLIS 。 假如可以刪除,因爲刪除的點後面的標號會減 11 ,

原创 [ DP 莫隊 ]「2017 山東一輪集訓 Day6」LOJ#6074 子序列

題解 #include<bits/stdc++.h> using namespace std; const int SZ=1<<25; char nc() { static char buf[SZ],*p1=buf,*p

原创 Codechef October Challenge 2019 Division 1 solutions

Chef and Maximum Star Value 顯然如果一個數後面有它的因數,那麼它一定不可能是最大值。先從後往前枚舉一遍把這些數去掉,再從前往後做一遍,每個數枚舉它所有倍數統計即可。 因爲每個數最多隻會做一次,時間複雜度

原创 [ 齊次線性遞推式 ] BZOJ4161 Shlw loves matrixI

假設轉移矩陣爲 AA 。 然後就是要求出 hAn−k+1hAn−k+1 。 AA 的特徵多項式爲 f(A)=Ak−∑ki=1aiAk−i=0f(A)=Ak−∑i=1kaiAk−i=0 。 所以 xn−k+1≡xn−k

原创 [ 容斥 斯特林數 ] Codeforces715E Complete the Permutations

題解 #include<bits/stdc++.h> using namespace std; const int N=510; const int P=998244353; int k,n,m,x; int nx[N],d[N]

原创 [ 決策單調性 分治 ] LOJ#535 花火

題解 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long

原创 [ 斯特林數 NTT ] [ Tjoi2016&Heoi2016 ] BZOJ4555 求和

題解 #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; c

原创 [ 分治 複雜度分析 ] [ NWERC2017 ] BZOJ5200 Factor-Free Tree

和bzoj4059一樣的套路。 #include<bits/stdc++.h> using namespace std; inline char nc(){ static char buf[100000],*p1=buf,

原创 [ ST表 並查集 樹的直徑 ] Codechef March Cook-Off 2018 Maximum Tree Path

先枚舉 gcdgcd ,把所有邊找出來,按照權值小的端點排序,然後從大到小枚舉邊,並查集維護直徑就好了。 時間複雜度 O(nAi−−√(logn+α))O(nAi(log⁡n+α)) 。 #include<bits/stdc

原创 [ 雜題 ] Codeforces923D Picking Strings

先瞎JB推一下,得到一些結論: B→AC→AAB→AAAC→CB\rightarrow AC \rightarrow AAB \rightarrow AAAC \rightarrow CB→AC→AAB→AAAC→C ,反

原创 Codechef March Challenge 2018 DIV 1 題解

Mix the Colors 顯然每次選最大的數加到一個數上是最優的,那麼答案就是 n−顏色種數n−顏色種數 。 代碼 Chef and Easy Problem 預處理出每個二進制位的前綴和,詢問時枚舉每一位貪心選就好了。

原创 [ 雜題 ] Codeforces955D Scissors

對於 tt 的每個前綴,雙指針掃一遍求出在 ss 中出現的最左的位置,對每個後綴求出最右的位置。然後枚舉 tt 中分割的位置就好了。 注意判斷 tt 在一個子串中出現的情況。 UPD: 感謝 lifelikes 指出錯誤

原创 [ 分治 決策單調性優化DP ] LOJ#6039. 「雅禮集訓 2017 Day5」珠寶

設 fi,jfi,j 表示售價 ≤i≤i 的珠寶,使用 jj 萬元的最大吸引力。轉移方程很容易寫出。 因爲售價相同的珠寶肯定是從最大吸引力開始取的,所以轉移的函數是上凸的。 將 jj 按 j mod ij mod i

原创 [ 雜題 ] Codeforces949E Binary Cards

發現答案中每個二進制數最多隻會出現一次。然後暴搜,過程中記下還有哪些數要表示,剪個枝就好了。 最多跑 219219 次。 #include<bits/stdc++.h> using namespace std; const i

原创 [ Manacher ] BZOJ3790

Manacher模板題 #include<bits/stdc++.h> using namespace std; #define fi first #define se second typedef pair<int,int> a