Professional Documents
Culture Documents
Linkbi:http://vn.spoj.com/problems/VOSSEVEN/
Gif[i]lsccxuchgmccs7lintipvcdili.
Gians[i]lsccxucdiixuthintrnxus.
Ddngnhnthynutxucdilistorac1xudii,2xudi(i1),
nucf[i]xudiistocraf[i]xudii,f[i]*(i2+1)xudi2
>Duytvngi,nuf[i]>0:
>ans[j]=ans[j]+f[i]*(ij+1),vij<=i.
Cuicnglinraccgitrimans[i]>0.
PTO(n)
Bi 2: VOSTRIBO
Dngkinthcvnhnmatrn:
(nhngbnnochabitcthvolinksautmhiu:
https://sites.google.com/site/minhnhatcqt/baiviet/kithuatlaptrinh/matrix)
Nhnxt:
T[i2]=T[i3]*0+T[i2]*1+T[i1]*0+F[i1]*0
T[i1]=T[i3]*0+T[i2]*0+T[i1]*1+F[i1]*0
T[i]=T[i3]*1+T[i2]*1+T[i1]*1+F[i1]*0
F[i]=T[i3]*1+T[i2]*1+T[i1]*1+F[i1]*1
Nntacbngsau
T[i3]
T[i2]
T[i1]
F[i1]
T[i2]
T[i1]
T[i]
F[i]
Vector(T[i3],T[i2],T[i1],F[i1])nhnvimatrn((0,0,1,1),(1,0,1,1),(0,1,1,1),(0,0,0,1))
sracVector(T[i2],T[i1],T[i],F[i])
Bi 3: VOSCOMPS
Cch lm tru:
-
Vi mi nhm:
1.
2.
3.
4.
5.
6.
6.1.
6.2.
6.3.
PT:
-
Bc 1: O(1).
Bc 2: O(N).
Bc 3: O(Q).
Bc 4: O(Q * PT(find)).
Bc 5: O(1).
Bc 6.2: O(PT(find)).
PSEUDOCODE:
DSU gm c 2 mng sau:
parent[x] = nh cha ca nh x
rank[x] = th hng ca nh x
bc khi to gi tr mc nh: gn parent[x] = x, rank[x] = 0
bc lu li trng thi ca DSU: khi to stack gm cc phn t c
3 tham s: u (nh c), p (nh cha c), r (th hng c).
find(x)
while x <> parent[x] do
x = parent[x]
return x
union(x, y)
x = find(x)
y = find(y)
if rank[x] < rank[y] then swap(x, y)
thm phn t c u = x, p = parent[x], r = rank[x] vo stack
thm phn t c u = y, p = parent[y], r = rank[y] vo stack
parent[y] = x
if rank[x] = rank[y] then rank[x] = rank[x] + 1
rollback()
while vn cn phn t trong stack do
u = u ca phn t trn cng stack
p = p ca phn t trn cng stack
r = r ca phn t trn cng stack
parent[u] = p
rank[u] = r
xo phn t trn cng ca stack
-