HDU 3038 How many Answers is wrong (with right and check set)

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)

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 Input
10 51 10 1007 10 281 3 324 6 416 6 1

Sample Output
1
and look up the set: if we know [1,3] and [4,6], then we know [1,6]. weighted Path Sum[i] represents the distance from the root node in the collection ...
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string > #include <iostream> #include <queue> #include <cmath> #include <map> #include <stack>  #include <bitset>using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i, n ) for (int i = 0; i < n; + + i) #define CLEAR (A, X) memset (A, x, sizeof a) typedef long long Ll;typedef pair& lt;int,int>pil;const int mod = 1000000007;const int Maxn=200000+10;int Pre[maxn],sum[maxn];//sum[i] represents the sum of the root nodes int n,m         ; int find (int x) {if (x!=pre[x]) {int f=pre[x];         Pre[x]=find (Pre[x]);     sum[x]+=sum[f];//to find a more energy-saving distance in the X-X collection. } return pre[x];}    int main () {int l,r,s;        while (~SCANF ("%d%d", &n,&m)) {REPF (i,0,n) pre[i]=i;        CLEAR (sum,0);        int ans=0;            while (m--) {scanf ("%d%d%d", &l,&r,&s);            L-=1; int Ra=find (l), RB=find (R); if (RA!=RB) {pre[ra]=rb;//with RB as root node SUM[RA]=SUM[R]-SUM[L]+S;//SUM[R]:R-&GT;RB;S:L-&G   T;r;sum[l]:l->r, RA-&GT;RB is required.} else if (RA==RB) {if (sum[l]-sum[r]!=s)            ans++;    }} printf ("%d\n", ans); } return 0;}


HDU 3038 How many Answers is wrong (with right and check set)

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.