成段更新的线段树- -!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
using namespace std;
#define maxn 1000010
#define l(i) ((i)<<1)
#define r(i) ((i)<<1|1)
struct node{
int left,right,mid,max,add;
}tr[maxn<<2];
void build(int l,int r,int k){
tr[k].max=0;
tr[k].add=0;
int mid=(l+r)>>1;
tr[k].left=l;
tr[k].right=r;
tr[k].mid=mid;
if(l==r)
return;
build(l,mid,l(k));
build(mid+1,r,r(k));
}
int max(int a,int b)
{
return a>b?a:b;
}
int check(int left,int right,int ind){
if(left<=tr[ind].left&&right>=tr[ind].right)
return tr[ind].max;
if(tr[ind].add){
tr[l(ind)].max+=tr[ind].add;
tr[l(ind)].add+=tr[ind].add;
tr[r(ind)].max+=tr[ind].add;
tr[r(ind)].add+=tr[ind].add;
tr[ind].add=0;
}
int tmp=0;
if(left<=tr[ind].mid) tmp=max(tmp,check(left,right,l(ind)));
if(tr[ind].mid<right) tmp=max(tmp,check(left,right,r(ind)));
return tmp;
}
void update(int left,int right,int ind){
if(left<=tr[ind].left&&tr[ind].right<=right){
tr[ind].max++;
tr[ind].add++;
return;
}
if(tr[ind].add)
{
tr[l(ind)].max+=tr[ind].add;
tr[l(ind)].add+=tr[ind].add;
tr[r(ind)].max+=tr[ind].add;
tr[r(ind)].add+=tr[ind].add;
tr[ind].add=0;
}
if(left<=tr[ind].mid) update(left,right,l(ind));
if(tr[ind].mid<right) update(left,right,r(ind));
tr[ind].max=max(tr[l(ind)].max,tr[r(ind)].max);
}
int main()
{
int t,n,i,j,a,b,tot,c=0,q;
//freopen("sample.txt","r",stdin);
scanf("%d",&t);
while(t--){
printf("Case %d:\n",++c);
tot=0;
scanf("%d%d",&n,&q);
build(1,1000000,1);
for(i=1;i<=q;i++){
scanf("%d%d",&a,&b);
--b;
if(check(a,b,1)<n)
{
update(a,b,1);
printf("%d ",i);
}
}
printf("\n\n");
}
// system("pause");
return 0;
}