题面
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 ti and a luminance xi. Formally, the i-th bulb will be turned on from the (2kti+1)-th second to the (2kti+ti)-th second, and it will be turned off from the (2kti+ti+1)-th second to the (2kti+2ti)-th second, k=0,1,2,… When the i-th bulb is on, its luminance will be xi, 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≤105) − 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×105.
Then in the next n lines, the i-th line contains two integers ti,xi (1≤ti,xi≤105) − 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])