天天看點

hdu 3038D - How Many Answers Are Wrong [kuangbin帶你飛]專題五 并查集How Many Answers Are Wrong

點選打開連結

2015級新生如何加入acm集訓隊? 

time limit: 2000/1000 ms (java/others)    memory limit: 32768/32768 k (java/others)

total submission(s): 4106    accepted submission(s): 1571

problem description

tt and ff are ... friends. uh... very very good friends -________-b

ff is a bad boy, he is always wooing tt to play the following game with him. this is a very humdrum game. to begin with, tt should write down a sequence of integers-_-!!(bored).

hdu 3038D - How Many Answers Are Wrong [kuangbin帶你飛]專題五 并查集How Many Answers Are Wrong

then, ff can choose a continuous subsequence from it(for example the subsequence from the third to the fifth integer inclusively). after that, ff will ask tt what the sum of the subsequence he chose is. the next, tt will answer ff's question. then, ff can redo

this process. in the end, ff must work out the entire sequence of integers.

boring~~boring~~a very very boring game!!! tt doesn't want to play with ff at all. to punish ff, she often tells ff the wrong answers on purpose.

the bad boy is not a fool man. ff detects some answers are incompatible. of course, these contradictions make it difficult to calculate the sequence.

however, tt is a nice and lovely girl. she doesn't have the heart to be hard on ff. to save time, she guarantees that the answers are all right if there is no logical mistakes indeed.

what's more, if ff finds an answer to be wrong, he will ignore it when judging next answers.

but there will be so many questions that poor ff can't make sure whether the current answer is right or wrong in a moment. so he decides to write a program to help him with this matter. the program will receive a series of questions from ff together with the

answers ff has received from tt. the aim of this program is to find how many answers are wrong. only by ignoring the wrong answers can ff work out the entire sequence of integers. poor ff has no time to do this job. and now he is asking for your help~(why

asking trouble for himself~~bad boy)

input

line 1: two integers, n and m (1 <= n <= 200000, 1 <= m <= 40000). means tt wrote n integers and ff asked her m questions.

line 2..m+1: line i+1 contains three integer: ai, bi and si. means tt answered ff that the sum from ai to bi is si. it's guaranteed that 0 < ai <= bi <= n.

you can assume that any sum of subsequence is fit in 32-bit integer.

output

a single line with a integer denotes how many answers are wrong.

sample input

10 5

1 10 100

7 10 28

1 3 32

4 6 41

6 6 1

sample output

1

題目大意:

找有幾個資料是錯誤的,具體我給你們樣例解釋,首先輸入一個m 和 n,

m表示有區間的最大值,然後有n行數 u, v, w

分别表示[u, v] == w,看有幾個沖突的

解題思路:

種類并查集,就是找u-1就行了,看是否能夠找到他們的父親是一樣的,

具體詳見代碼

樣例解釋:

1 - 10 -> 100

7 - 10 ->28

1 - 3 -> 32

4 - 6-> 41

6 - 6 -> 1 

可以将1-3和4-6結合 == 1-6,然後在與7-10結合 == 1-10

32+41==73  + 28==101!=100

是以有一個是錯誤的

上代碼: