岳阳网站制作,网站建设的利益分析,宿迁网站建设多少钱,做网站备案要多久题意#xff1a;长为n的串#xff0c;给你m个区间#xff0c;这些区间内元素不重复#xff0c;问这样的串字典序最小为#xff1f; 思路#xff1a;用set保存当前能插入的元素#xff0c;这样就能直接插入最小元素了。对操作按l排序#xff0c;因为排过的不用排#x…题意长为n的串给你m个区间这些区间内元素不重复问这样的串字典序最小为 思路用set保存当前能插入的元素这样就能直接插入最小元素了。对操作按l排序因为排过的不用排所以两个指针LR是一直右移的。L右移肯定是增加set中元素R右移有两种可能一是L在R右边R只是负责赶路赶到操作区间二是L在R左边那么R右移是在扩大区间并且对数组中元素进行插入。 代码 #includecstdio
#includevector
#includeset
#includequeue
#includecstring
#includestring
#includecmath
#includecstdlib
#includealgorithm
#define ll long long
const int maxn 1000005;
const int maxm 1000005;
const int MOD 1e7;
const int INF 0x3f3f3f3f;
using namespace std;
struct node{int l,r;
}q[maxn];
bool cmp(node a,node b){return a.l b.l? a.r b.r : a.l b.l;
}
int ans[maxn];
int main(){int T;int n,m;scanf(%d,T);while(T--){memset(ans,0,sizeof(ans));scanf(%d%d,n,m);setint s;for(int i 1;i n;i){s.insert(i);}for(int i 0;i m;i)scanf(%d%d,q[i].l,q[i].r);sort(q,qm,cmp);for(int i q[0].l;i q[0].r;i){ans[i] *s.begin();s.erase(ans[i]);}int L q[0].l,R q[0].r;for(int i 1;i m;i){while(L q[i].l){if(ans[L] ! 0) s.insert(ans[L]);L;}while(R q[i].r){if(L R){if(ans[R] ! 0) s.insert(ans[R]);R;}else{if(L R){if(ans[R] 0){ans[R] *s.begin();s.erase(ans[R]);}else s.erase(ans[R]);R;if(ans[R] 0){ans[R] *s.begin();s.erase(ans[R]);}else s.erase(ans[R]);}else{R;if(ans[R] 0){ans[R] *s.begin();s.erase(ans[R]);}}}}}for(int i 1;i n;i){if(i ! 1) printf( );if(ans[i] 0) printf(1);else printf(%d,ans[i]);}printf(\n);}return 0;
} 转载于:https://www.cnblogs.com/KirinSB/p/9408749.html