How Many Answers Are Wrong

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24151    Accepted Submission(s): 8191

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

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
 
Source
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  3033 3035 3036 3037 3031 
 

Statistic | Submit | Discuss | Note

题意

思路

CODE

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <assert.h>
#include <vector> #define dbg(x) cout << #x << "=" << x << endl using namespace std;
typedef long long LL;
const int maxn = 4e5 + ; int fa[maxn];
int n,m,ans,cnt;
int sum[maxn];
//vector <int> v; void init()
{
for(int i = ; i <= maxn; i++) {
fa[i] = i;
}
} int fid(int x)
{
if(x != fa[x]) {
int r = fa[x];
fa[x] = fid(fa[x]);
sum[x] += sum[r];
}
/*int i,j;///路径压缩
i = x;
while(fa[i] != r) {
j = fa[i];
fa[i] = r;
i = j;
}
return r;*/
return fa[x];
} void join(int r1, int r2, int x)///合并
{
int fidroot1 = fid(r1), fidroot2 = fid(r2);
if(fidroot1 == fidroot2) {
if(sum[r1] - sum[r2] != x) {
++ans;
}
}
else {
fa[fidroot1] = fidroot2;
sum[fidroot1] = sum[r2] - sum[r1] + x;
}
} template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} namespace _buff {
const size_t BUFF = << ;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, , BUFF, stdin);
}
return ib == ie ? - : *ib++;
}
} int qread() {
using namespace _buff;
int ret = ;
bool pos = true;
char c = getc();
for (; (c < '' || c > '') && c != '-'; c = getc()) {
assert(~c);
}
if (c == '-') {
pos = false;
c = getc();
}
for (; c >= '' && c <= ''; c = getc()) {
ret = (ret << ) + (ret << ) + (c ^ );
}
return pos ? ret : -ret;
} int main()
{
while(scanf("%d %d",&n,&m) != EOF) {
init();
memset(sum, , sizeof(sum));
ans = ;
for(int i = ; i <= m; ++i) {
int a,b,x;
scanf("%d %d %d",&a, &b, &x);
a -= ;
join(a,b,x);
}
cout << ans << endl;
}
return ;
}

最新文章

  1. android Gui系统之SurfaceFlinger(2)---BufferQueue
  2. java中实现定时功能
  3. JS常用自定义方法
  4. windows无法安装到这个磁盘怎样解决
  5. 【csuoj1014】 西湖三人行
  6. 百度语音识别(Baidu Voice) Android studio版本
  7. Customer IEnuramble Extension
  8. codeforces C. Vasily the Bear and Sequence 解题报告
  9. Java中String对象的不可变性
  10. Java设计模式07:常用设计模式之装饰器模式(结构型模式)
  11. 为Android安装BusyBox
  12. 推荐一些socket工具,TCP、UDP调试、抓包工具 推荐一些socket工具,TCP、UDP调试、抓包工具
  13. Nginx各版本的区别
  14. css Tab选项卡1
  15. CodeForces 566D 并查集集合合并
  16. 关于IP网段间互访的问题—路由是根本(转)
  17. (OK) Linux epoll模型—socket epoll server client chat
  18. http头部 Expect
  19. python3之迭代器&amp;生成器
  20. zTree节点重叠或者遮挡

热门文章

  1. Ubuntu 18.04 MATLAB 安装及配置
  2. SpringBoot图文教程7—SpringBoot拦截器的使用姿势这都有
  3. The finally block does not always execute in try finally
  4. c语言心形告白代码实现
  5. C++中的public、protected和private
  6. 从零开始一个个人博客 by asp.net core and angular(一)
  7. postman界面按钮
  8. beego框架之orm模块——mysql
  9. .Net Core程序最终只产生1个exe
  10. JS DOM创建节点