热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

杭电多校第一场D题

闲来无事,看了下牛客多校的题目,嘴炮了几题,顺手用txt写了这题。先附上题面ProblemDescriptionChiakihasanar

闲来无事,看了下牛客多校的题目,嘴炮了几题,顺手用txt写了这题。先附上题面

Problem Description
Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (li<jr), aiajholds.
Chiaki would like to find a lexicographically minimal array which meets the facts.

 

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains two integers n and m (1n,m105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1lirin).

It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.

 

Output
For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.

 

Sample Input
3 2 1 1 2 4 2 1 2 3 4 5 2 1 3 2 4

 

Sample Output
1 2 1 2 1 2 1 2 3 1 1
解法大概就是将区间按左端点排序&#xff0c;然后用类似尺取的方法&#xff0c;加上小顶堆&#xff0c;一个个的将数填进去

1 #include
2 #include
3 #include
4 #include
5 using namespace std;
6 const int maxn &#61; 1e5&#43;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;ii){
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;ii){
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 }

 

转:https://www.cnblogs.com/yZiii/p/9361358.html



推荐阅读
author-avatar
qlb
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有