HDU 3038-how Many Answers is wrong

Source: Internet
Author: User

Problem Descriptiontt and FF are ... friends. Uh ... very very good friends-________-b

FF is a bad boy, he's always wooing TT-play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of integers-_-!! (bored).

Then, FF can choose a continuous subsequence from it (for example the subsequence from the third to the fifth integer inclu sively). After that, FF would ask TT what's the sum of the subsequence he chose is. The next, TT'll answer FF ' s question. Then, the 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 @ all. To punish FF, she often tells FF the wrong answers on purpose.

The bad boy isn't a fool man. FF detects some answers is incompatible. Of course, these contradictions make it difficult to calculate the sequence.

However, TT is a nice and lovely girl. She doesn ' t has the heart to is hard on FF. To save time, she guarantees the answers be all right if there is no logical mistakes indeed.

What's more, if FF finds a answer to be wrong, he'll ignore it when judging next answers.

But there'll be, so many questions, the poor FF can ' t make sure whether, the current answer are right or wrong in a moment. So he decides-to-write a program-to-help him with this matter. The program would receive a series of questions from FF together with the answers FF have received from TT. The aim of this program was to find what many answers is wrong. Only by ignoring the wrong answers can FF work out the entire sequence of integers. Poor FF has no time-to-do job. And now he's asking for your help~ (what 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 the sum from Ai to Bi are Si. It ' s guaranteed that 0 < Ai <= Bi <= N.

You can assume this any sum of subsequence are fit in 32-bit integer.

Output

A single line with an integer denotes how many answers is wrong.

Sample Input

Ten 1007 281 3 324 6 416 6 1 Sample Output1

Approximate test instructions:

Kids play games, there are n number, you do not know their values, and then there are m rows, each line A, B, C, the number of A to B is the number of C (contains the numbers of A and b);

However, some of the M-line numbers are wrong, which is in conflict with the conditions given above, requiring you to output the wrong number of lines at the end.

Problem Solving Ideas:

Take the right and check the set.

If there is a 3->6, 7->10, obviously, you put 7--,3--, it becomes 2->10; can put into the same set;

Compare with the rest of the same set;

1#include <cstdio>2 using namespacestd;3 intsum[200005];4 intf[200005];5 intsfintx) {6     if(X==f[x])returnx;7     Else{8         intTEMP=F[X];//Save the parent node and change it first9f[x]=SF (f[x]);TenSUM[X]+=SUM[TEMP];//length:x->root = x->father + father->root One         returnF[x]; A     } - } - intMain () { the     intn,m; -      while(~SCANF ("%d%d",&n,&m)) { -          for(intI=0; i<=n;i++) f[i]=i,sum[i]=0; -         intl,r,s,ans=0; +          for(intI=1; i<=m;i++){ -scanf"%d%d%d", &l,&r,&s); l--; +             intA=SF (l);//rot_l A             intB=SF (R);//Rot_r at             if(a>b) { -f[a]=b; -Sum[a]=sum[r]-sum[l]-s;//a->b = R->b-l->a-l->r -}Else if(a<b) { -f[b]=A; -sum[b]=sum[l]-sum[r]+s; in}Else{//if it's the same set -                 if(sum[r]-sum[l]!=s) ans++; to             } +} printf ("%d\n", ans); -}return 0; the}

HDU 3038-how Many Answers is wrong

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.