//题意:茜茜学姐的情人节到了!众所周知,茜茜学姐喜欢帅气的学弟,所以她当然有很多学弟送的花瓶,据不完全统计,茜茜学姐有N个花瓶(标号为0~ N-1)。当然茜茜学姐也是个魅力四射的男孩子,所以他也自然会在这天收到很多的花花,当他在情人节这天收到花花时时,他会随机的选择一个瓶子A,
//从它开始遍历A,A+1, A+2, ..., N-1号瓶子,遇到空瓶子的话就放一朵花进去,直到花放完或没有瓶子,剩下的花将被残忍的丢弃。有时,他也会清理标号从a到b的花瓶(a <= b).花瓶里的花会被丢弃。任性又帅气的茜茜学姐!
//思路:就是二分维护边界点,然后用线段树维护就行(我这里拆开写了,这样思路感觉清晰一点,只是这样复杂度是O(loglog n))
#include<bits/stdc++.h>
using namespace std;
const int N = 50010;
struct bt {
int num;//区间装满花的瓶子数
int tag;//清空花标记,装满花标记
}seg[4 * N];
int T, n, m;
void update(int id) {
seg[id].num = seg[id * 2].num + seg[id * 2 + 1].num;
}
void build(int id, int l, int r) {
if (l == r) {
seg[id].num = 0;
seg[id].tag = -1;
return;
}
int mid = (l + r) / 2;
build(2 * id, l, mid); build(2 * id + 1, mid + 1, r);
update(id);
}
void pushdown(int id, int l, int r) {
int mid = (l + r) / 2;
if (seg[id].tag == -1) return;
seg[2 * id].tag = seg[2 * id + 1].tag = seg[id].tag;
seg[2 * id].num = (mid - l + 1) * seg[id].tag;
seg[2 * id + 1].num = (r - (mid + 1) + 1) * seg[id].tag;
seg[id].tag = -1;
return;
}
int sum(int id, int l, int r, int ql, int qr) {
if (l == ql && r == qr) {
return seg[id].num;
}
pushdown(id, l, r);
int mid = (l + r) / 2;
int ans = 0;
if (ql <= mid) return sum(2 * id, l, mid, ql, qr);
else if (qr > mid) return sum(2 * id + 1, mid + 1, r, ql, qr);
else {
return sum(2 * id, l, mid, ql, mid) + sum(2 * id + 1, mid + 1, r, mid + 1, qr);
}
}
void modify(int id, int l, int r, int ql, int qr, int d) {
if (l == ql && r == qr) {
seg[id].num = ((r - l) + 1) * d;
seg[id].tag = d;
return;
}
pushdown(id, l, r);
int mid = (l + r) / 2;
if (qr <= mid) modify(2 * id, l, mid, ql, qr, d);
else if (ql > mid) modify(2 * id + 1, mid + 1, r, ql, qr, d);
else {
modify(2 * id, l, mid, ql, mid, d);
modify(2 * id + 1, mid + 1, r, mid + 1, qr, d);
}
update(id);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
build(1, 1, n);
int od, a, b;
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &od, &a, &b);
a++;
if (od == 1) {
int emtbt = sum(1, 1, n, a, n);//花数
emtbt = n - a + 1 - emtbt;//空瓶数
//cout << emtbt << endl;
if (emtbt == 0)
{
puts("Can not put any one.\n");
continue;
}
if (emtbt < b) b = emtbt;
int l = a, r = n, pl = 0, pr = n;
while (l <= r) {
int mid = (l + r) / 2;
int w = sum(1, 1, n, a, mid);
w = mid - a + 1 - w;//空瓶数
if (w >= 1) {
pl = mid;
r = mid - 1;
}
else l = mid + 1;
}
l = pl, r = n;
while (l <= r) {
int mid = (l + r) / 2;
int w = sum(1, 1, n, pl, mid);
w = mid - pl + 1 - w;//空瓶数
if (w >= b) {
pr = mid;
r = mid - 1;
}
else l = mid + 1;
}
//cout << pl << " " << pr << endl;
modify(1, 1, n, pl, pr, 1);
printf("%d %d\n", pl - 1, pr - 1);
}
else {
b++;
int w = sum(1, 1, n, a, b);
modify(1, 1, n, a, b, 0);
printf("%d\n", w);
}
}
puts("");
}
return 0;
}