闲来无事,看了下牛客多校的题目,嘴炮了几题,顺手用txt写了这题。先附上题面
Chiaki would like to find a lexicographically minimal array which meets the facts.
The first line contains two integers n and m (1≤n,m≤105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.
1 #include
2 #include
3 #include
4 #include
5 using namespace std;
6 const int maxn = 1e5+7;
7 struct node{
8 int l,r;
9 }a[maxn];
10 int vis[maxn];
11 int ans[maxn];
12 priority_queue <int, vector<int>, greater<int> > q;
13
14 bool cmp(node a,node b){
15 return a.l < b.l;
16 }
17
18 int main(){
19 int T;
20 scanf("%d",&T);
21 while(T--){
22 memset(vis,0,sizeof(vis));
23 memset(ans,0,sizeof(ans));
24 while(!q.empty()) q.pop();
25 int n,m;
26 scanf("%d%d",&n,&m);
27 for(int i&#61;1;i<&#61;n;&#43;&#43;i) q.push(i);
28 for(int i&#61;0;i
29 scanf("%d%d",&a[i].l,&a[i].r);
30 }
31
32 sort(a,a&#43;m,cmp);
33 int l &#61; 0,r &#61; 0;
34 for(int i&#61;0;i
35 while(l < a[i].l){
36 if(ans[l] !&#61; 0)
37 q.push(ans[l]);
38 &#43;&#43; l;
39 }
40 while(r <&#61; a[i].r){
41 if(r >&#61; a[i].l){
42 ans[r] &#61; q.top();
43 q.pop();
44 }
45 &#43;&#43; r;
46 }
47 }
48 for(int i&#61;1;i<&#61;n;&#43;&#43;i){
49 if(ans[i] &#61;&#61; 0)
50 ans[i] &#61; 1;
51 }
52 for(int i&#61;1;i<&#61;n;&#43;&#43;i){
53 if(i !&#61; 1) printf(" ");
54 printf("%d",ans[i]);
55 }
56 puts("");
57 }
58 return 0;
59 }