題面:luogu3823
題意:n
nn只蚯蚓,每只蚯蚓有乙個≤
6\le 6
≤6的長度,初始時每只蚯蚓一支隊伍。給出m
mm個操作。
三種操作:
將以i
ii結尾的隊伍和以j
jj開頭的隊伍合併,且i
ii的隊伍在前。
將i
ii和i
ii後面乙隻蚯蚓處斷開,分為兩支隊伍。
定義以第x
xx只蚯蚓開始的長度為k
kk的數字串為:從x
xx開始的連續k
kk只蚯蚓,它們的長度數字連成的字串。定義給定乙個字串s
ss和整數k
kk,s
ss的每個長度為k
kk的子串s′s'
s′,定義f(s
′)
f(s')
f(s′
)為有多少只蚯蚓開頭的長度為k
kk的數字串等於s′s'
s′。詢問∏s′
f(s′
)\prod _ f(s')
∏s′f(
s′)。n≤
2×10
5n \le 2 \times 10^5
n≤2×10
5,m≤3×
10
5m \le 3 \times 10^5
m≤3×10
5,k≤
50k \le 50
k≤50
,∑ ∣s
∣≤10
7\sum _ \le 10^7
∑∣s∣≤
107題解:首先對於隊伍的操作,用雙向鍊錶即可維護。
對於數字串,可以用雜湊維護。
觀察到k
kk的範圍很小,意味著每次隊伍發生合併或斷開時,只會影響到k
kk只蚯蚓的數字串雜湊值。
因此每次暴力更新雜湊值的複雜度為o(k
2)
o(k^2)
o(k2)
建一張雜湊表,關鍵字為雜湊值。查詢時直接查雜湊表即可。
#include
using
namespace std;
inline
intread()
while
(c >=
'0'&& c <=
'9') x = x *
10+ c -
'0', c =
getchar()
;return x * f ;
}typedef
unsigned
long
long ull ;
const
int maxn =
2e5+
10, base =
131, mod =
998244353
, hash_mod =
19260817
;const
int maxs =
1e7+10;
int a[maxn]
, nxt[maxn]
, pre[maxn]
;ull p[maxn]
;char str[maxs]
;struct hash_table
len[
++ tot]
= l; val[tot]
= v; s[tot]
= ss ;
nxt[tot]
= head[tmp]
; head[tmp]
= tot ;
}inline
int query (ull ss,
int l)
}hash ;
inline
void link (
int x,
int y)}}
inline
void cut (
int x)
} nxt[x]
= pre[y]=0
;}inline
int query (
int k)
return res ;
}int
main()
p[0]
=1;for
(int i =
1; i <= n; i ++
) p[i]
= p[i -1]
* base ;
while
(m --
)else
if(op ==2)
else
}return0;
}
Luogu4770 NOI2018 你的名字
題面 luogu4770 題意 給定乙個串s ss。每次詢問給出乙個字串t tt,問t tt有多少個不同的子串使得其也不是s l r s l r s l r 的子串。s 5 1 05 s le 5 times 10 5 s 5 105,q 1 05 q le 10 5 q 105,t 10 6 su...
Luogu 2254 NOI2005 瑰麗華爾茲
簡單dp,設 f 表示第i個時間段,鋼琴處在 j,k 位置移動距離的最大值,那麼有轉移 f max f f max f 其中 j dx len leq a leq j 1 k dy len leq b leq k 1 len ed st 1 其實就是乙個滑動視窗,考慮到轉移順序,就是寫四遍單調佇列 ...
luogu1106 刪數問題(NOI1994)
時空限制 1000ms 128mb 鍵盤輸入乙個高精度的正整數n,去掉其中任意k個數字後剩下的數字按原左右次序將組成乙個新的正整數。程式設計對給定的n和k,尋找一種方案使得剩下的數字組成的新數最小。輸出應包括所去掉的數字的位置和組成的新的整數。n不超過250位 輸入資料均不需判錯。輸入格式 n 高精...