HDU 3038 how many answers are wrong (and query set)

Source: Internet
Author: User
How many answers are wrong

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1210 accepted submission (s): 486

Problem descriptiontt and FF are... friends. Uh... very good friends-________-B

FF
Is a bad boy, he is always wooing TT to play the following game
He. This is a very humdrum game. To begin with, TT shocould write down
Sequence of integers -_-!! (Bored ).


Then,
FF can choose a continuous subsequence from it (for example
Subsequence from the third to the specified th integer within sively). After
That, FF will ask tt what the sum of the subsequence he chose is.
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.
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.
Course, these contradictions make it difficult to calculate
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
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 empty 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
Series of questions from FF together with the answers FF has encoded ed
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)

 

Inputline
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.

 

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

 

Sample input10 51 10 1007 10 281 3 324 6 416 6 1

 

Sample output1 analysis: This question is exactly the same as HDU (3047 ..... However, when looking for a set, you must understand this sentence because the data provided each time is actually in a set. There is also a change in the data range... Up/down Code Not dynamic. For detailed analysis, see HDU 3074.
# Include <iostream> # Include <Cstdio> # Include <Cstring># Include <Algorithm> # Define Maxnum200005 Using   Namespace  STD;  //  Father: stores the subscript of the parent node of the node,  //  Dist stores the sum of nodes to the parent node  Int  Father [maxnum], DIST [maxnum];  Int  N, m;  Int Find_father ( Int A ){  If (Father [a] =) Return  A;  Int TEM = Father [a]; father [A] = Find_father (father [a]); Dist [A] + = Dist [TEM];  Return  Father [a];}  Void Union_set ( Int A, Int B, Int X ){  Int Ra = Find_father ();  Int RB = Find_father (B); father [RB] = RA; Dist [RB] = DIST [a] + X- Dist [B];}  Int  Main (){  Int  A, B, Ra, Rb, X, conflics;  While (Scanf ( "  % D " , & N, & M )! = EOF) {memset (Dist,  0 , Sizeof  (DIST ));  For ( Int I = 0 ; I <= N; I ++ ) Father [I] = I; conflics = 0  ;  For ( Int I =0 ; I <m; I ++ ) {Scanf (  "  % D  " , & A, & B ,& X); --; //  Note that here I have wrong several times Ra = Find_father (a); RB = Find_father (B );  If (RA = RB ){  If (Dist [B]-Dist [a]! = X) conflics ++ ;}  If (Ra! = RB) union_set (a, B, x);} printf (  "  % D \ n  "  , Conflics );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.