2020CCPC绵阳 J.Joy of Handcraft(两种解法)

题面

Little Horse always does some handcrafts, which is full of joy. This time, he builds a circuit that can turn on and off the bulbs periodically.

There are n bulbs in the circuit, the i-th of which has a period t​i​​ and a luminance x​i​​. Formally, the i-th bulb will be turned on from the (2kt​i​​+1)-th second to the (2kt​i​​+t​i​​)-th second, and it will be turned off from the (2kt​i​​+t​i​​+1)-th second to the (2kt​i​​+2t​i​​)-th second, k=0,1,2,… When the i-th bulb is on, its luminance will be x​i​​, otherwise its luminance will be 0.

Now, Little Horse wants to know, for each second from the first second to the m-th second, what’s the maximum luminance among all the bulbs.

Input
The first line of the input contains an integer T (1≤T≤100) − the number of test cases.

The first line of each test case contains two integers n,m (1≤n,m≤10​5​​) − the number of bulbs, and the number of integers you need to output. The sum of n and the sum of m will not exceed 2×10​5​​.

Then in the next n lines, the i-th line contains two integers t​i​​,x​i​​ (1≤t​i​​,x​i​​≤10​5​​) − the period and the luminance of the i-th bulb.

Output
The x-th test case begins with Case #x:, and there follow m integers. The i-th integer indicates the maximum luminance among all the bulbs in the i-th second. If no bulb is on in the i-th second, output 0.

Sample Input
3
2 3
1 1
2 2
2 5
1 2
2 3
3 3
1 1
1 2
1 3
Sample Output
Case #1: 2 2 1
Case #2: 3 3 2 0 3
Case #3: 3 0 3

题解

线段树

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 4e5+5;

struct bub {
   
	int t, x;
}b[MAXN];

bool cmp(bub a, bub b) {
   
	return a.x>b.x;
}

int node[MAXN], l[MAXN], r[MAXN], tag[MAXN];

//vis数组判断某个周期是否处理过
bool vis[MAXN];

void build(int ll, int rr, int num) {
   
	l[num] = ll; r[num] = rr;
	if(ll == rr) return;
	int mid = (ll+rr)>>1;
	build(ll, mid, num*2);
	build(mid+1, rr, num*2+1);
}

void pushdown(int num) {
   
    if(tag[num] == 0) return;
    int lch = num*2, rch = num*2+1;
	//如果某个时间已经处理过了,就不要再处理了
	if(!node[lch]) 
		node[lch] = tag[lch] = tag[num];
	if(!node[rch])
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值