HDU 3038 How many Answers is wrong

Source: Internet
Author: User

Problem Description:tt 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) 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 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. Outputa single line with an integer denotes how many answers is wrong.

Sample Input10 5 1 7 1 3 + 4 6 6 6 1 Sample OUTPUT1 Test Instructions: Ai~bi and is Si, now total N number, give you M information, judge the wrong information how many. Then Ai~bi and Si can be seen as 1~bi and larger si than 1~ai-1 + ——————— + ——————————————— + A C B know A~b and for the a~c of the and for 40, while C~b's and is 50, there is a false saying
#include <stdio.h>#defineN 200010intF[n], r[n], N;voidInit () {inti;  for(i =0; I <= N; i++) {F[i]=i; R[i]=0; }}intFind (intx) {    intK =F[x]; if(F[x]! =x) {f[x]=Find (f[x]); R[X]= r[k]+R[x]; }    returnf[x];}intMain () {intm, A, B, C, Na, NB, ans;  while(SCANF ("%d%d", &n, &m)! =EOF)        {Init (); Ans=0;  while(m--) {scanf (" %d%d%d", &a, &b, &c); A--;//Like 6~10 and is 1~10 and more than the part of the and more, need to be a minus 1 na=Find (a); NB=Find (b); if(na = NB && c+r[a]! =R[b]) ans++; Else if(Na <nb) {F[NB]=na; R[NB]= (C+r[a])-R[b]; }            Else if(Na >nb) {F[na]=NB; R[na]= r[b]-(r[a]+c); }} printf ("%d\n", ans); }    return 0;}

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.