裸==
1.从x更新到y-1
2.注意格式
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 #define n 1000000 6 int ans[100005],maxv[4000005],addv[4000005]; 7 void update(int o,int l,int r,int y1,int y2,int v) 8 { 9 int mid=l+(r-l)/2; 10 if (y1<=l&&y2>=r) addv[o]+=v; 11 else{ 12 if (y1<=mid) update(o*2,l,mid,y1,y2,v); 13 if (y2>mid) update(o*2+1,mid+1,r,y1,y2,v); 14 } 15 maxv[o]=0; 16 if (r>l) maxv[o]=max(maxv[o*2],maxv[o*2+1]); 17 maxv[o]+=addv[o]; 18 } 19 int query(int o,int l,int r,int y1,int y2,int add) 20 { 21 int mid=l+(r-l)/2,tmp=0; 22 if (y1<=l&&y2>=r) return maxv[o]+add; 23 else{ 24 if (y1<=mid)tmp=max(tmp,query(o*2,l,mid,y1,y2,add+addv[o])); 25 if (y2>mid)tmp=max(tmp,query(o*2+1,mid+1,r,y1,y2,add+addv[o])); 26 return tmp; 27 } 28 } 29 int main() 30 { 31 int T,t,p,k,m,i,tmp,x,y; 32 scanf("%d",&T); 33 for (t=1;t<=T;t++) 34 { 35 memset(maxv,0,sizeof(maxv)); 36 memset(addv,0,sizeof(addv)); 37 scanf("%d%d",&k,&m); 38 p=0; 39 for (i=1;i<=m;i++) 40 { 41 scanf("%d%d",&x,&y); 42 y--; 43 tmp=query(1,1,n,x,y,0); 44 if (tmp>=k) continue; 45 ans[++p]=i; 46 update(1,1,n,x,y,1); 47 } 48 printf("Case %d:\n",t); 49 for (i=1;i<=p;i++) printf("%d ",ans[i]); 50 printf("\n\n"); 51 } 52 return 0; 53 }