Gym - 101350F Monkeying Around

Problem

When the monkey professor leaves his class for a short time, all the monkeys go bananas. N monkeys are lined up sitting side by side on their chairs. They each have the same joke book. Before the professor returns, M jokes were heard.

Each of the M jokes are said in the order given and have the following properties:

xi - position of the monkey who said it.

li – index of the joke in the book.

ki – volume the monkey says that joke.

When the monkey at position xi says the joke li, all monkeys at a distance less than or equal to ki from that monkey (including the monkey who said the joke) will fall off their chairs in laughter if they have never heard the joke li before.

If the joke li has been heard anytime during the past before, and the monkey hears it again, then he will sit back up in his chair.

A monkey can fall off his chair more than once (every time he hears a new joke), and if he is already on the ground and hears a new joke, he will stay on the ground.

Can you figure out how many monkeys will be in their seats by the time the professor comes back?

Input

The first line of input is T – the number of test cases.

The first line of each test case is N, M (1 ≤ N ≤ 105) (1 ≤ M ≤ 105) – the number of monkeys in the class, and the number of jokes said before the professor returns.

The next M lines contain the description of each joke: xi, li, ki (1 ≤ xi ≤ N) (1 ≤ li ≤ 105) (0 ≤ ki ≤ N).

Output

For each test case, output on a line a single integer - the number of monkeys in their seats after all jokes have been said.

Example
Input

1
10 7
3 11 0
3 11 2
5 12 1
8 13 2
7 11 2
10 12 1
9 12 0

Output

3

先简单说一下题意,大致意思就是说有猴子一个接着一个坐成一排,他们之中的几个会说笑话,谁说的笑话他们说的笑话的种类与声音的大小就是给的输入。当一只猴子听到他没听过的笑话时就会瘫倒地上(O_O)。当他听到他听过的笑话时就会坐回椅子上。问输入完毕后在椅子上的猴子有多少只。

看完题目后仔细想想,会发现其实只有每只猴子最后听到的笑话会影响他们的状态。所以我想到了用线段树去维护他们最后听到的状态。同时,因为访问线段树一定是从左到右的,所以我用了一个数组前缀和去求每个猴子听到的不同故事的次数。

以下便是代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define met(a, b) memset(a, b, sizeof(a))
#define ll long long

using namespace std;

struct node {
   
    int l, r, w, lazy;
    node *lson, *rson;
}treespace[1000000];
struct que {
   
    int w, next;
}DATA[600000];

pair<int, int> head[200010];
int sta[100100]
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值