提交时间:2023-11-10 22:27:03
运行 ID: 109664
#include<bits/stdc++.h> using namespace std; struct aaa{ int id,cnt; }a1[20005]; struct gk{ int l,r; }peo[1005]; int t,k,n,a[20005],cnt1,ans; bool b[20005]; bool cmp(aaa x,aaa y){ //if(!y.id)return 0; // if(x.id == 0){ // cout<<x.id<<","<<x.cnt<<endl; // } // if(y.id == 0){ // cout<<y.id<<","<<y.cnt<<endl; // } // if(b[x.id]||b[y.id])return b[x.id]; if(x.cnt!=y.cnt)return x.cnt>y.cnt; return abs(x.id-10001)<abs(y.id-10001); } int main(){ cin>>t; while(t--){ cin>>k>>n; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); ans=0; for(int i=1;i<=n;i++){ cin>>peo[i].l>>peo[i].r; if(peo[i].l>peo[i].r)swap(peo[i].l,peo[i].r); peo[i].l+=10001; peo[i].r+=10001; for(int j=peo[i].l;j<=peo[i].r;j++){ a[j]++; } } for(int i=1;i<=n;i++){ cnt1=min(k,peo[i].r-peo[i].l+1); for(int j=peo[i].l;j<=peo[i].r;j++){ a1[j].id=j; a1[j].cnt=a[j]; } //cout<< i << ": "<< peo[i].l << " - " << peo[i].r+1 << endl; sort(a1+peo[i].l,a1+peo[i].r+1,cmp); //cout<<i<<":"; for(int j=0;j<cnt1;j++){ b[a1[peo[i].l+j].id]=1; //cout<<a1[peo[i].l+j].id-10001<<" "; } //cout<<endl; } for(int i=1;i<=20001;i++){ if(b[i])ans++; } cout<<ans<<endl; for(int i=1;i<=20001;i++){ if(b[i])cout<<i-10001<<endl; } } return 0; }