#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = (maxn<<5) + 5;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
int T, n, m;
int lazy[maxn<<2], sum[maxn<<2];
void build(int rt, int l, int r){
lazy[rt] = -1; sum[rt] = 0;
if(l == r) return;
int mid = (l + r) >> 1;
build(lson); build(rson);
}
void pushdown(int rt, int l, int r){
if(~lazy[rt]){
int mid = (l + r) >> 1;
lazy[rt<<1] = lazy[rt<<1|1] = lazy[rt];
if(lazy[rt] == 1) sum[rt<<1] = mid - l + 1, sum[rt<<1|1] = r - mid;
if(lazy[rt] == 0) sum[rt<<1] = sum[rt<<1|1] = 0;
lazy[rt] = -1; return;
}
}
void update(int rt, int l, int r, int L, int R, int val){
if(L <= l && r <= R){
lazy[rt] = val;
if(val == 1) sum[rt] = r - l + 1;
if(val == 0) sum[rt] = 0;
return;
}
pushdown(rt, l, r);
int mid = (l + r) >> 1;
if(L <= mid) update(lson, L, R, val);
if(R > mid) update(rson, L, R, val);
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
int query(int rt, int l, int r, int L, int R){
if(L <= l && r <= R) return sum[rt];
int mid = (l + r) >> 1;
int ans = 0;
pushdown(rt, l, r);
if(L <= mid) ans += query(lson, L, R);
if(R > mid) ans += query(rson, L, R);
return ans;
}
int binary(int L, int R, int num){
int l = L;
int r = R;
while(l < r){
int mid = (l + r) >> 1;
if(mid - L + 1 - query(1, 1, n, L, mid) >= num)
r = mid;
else
l = mid + 1;
}
return r;
}
int main()
{
scanf("%d", &T);
while(T --){
int l, r, x, y, op;
scanf("%d %d", &n, &m);
build(1, 1, n);
for(int i = 1 ; i <= m ; ++ i){
scanf("%d", &op);
if(op == 1){
scanf("%d %d", &x, &y);
x ++;
int ans = n - x + 1 - query(1, 1, n, x, n);
if(ans == 0){
cout << "Can not put any one." << endl;
continue;
}
l = binary(x, n, 1);
r = binary(x, n, min(ans, y));
cout << l - 1 << ' ' << r - 1 << endl;
update(1, 1, n, l, r, 1);
}
else{
scanf("%d %d", &l, &r);
l ++ ; r ++;
cout << query(1, 1, n, l, r) << endl;
update(1, 1, n, l, r, 0);
}
}
cout << endl;
}
return 0;
}
Vases and Flowers(二分+线段树)
最新推荐文章于 2019-10-16 23:25:12 发布