首页 > 其他 > 详细

P1801 黑匣子_NOI导刊2010提高(06)

时间:2019-10-09 15:12:16      阅读:102      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1 #include<iostream>
 2 #include<queue>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 priority_queue<int>heapb;
 7 priority_queue<int, vector<int>, greater<int>>heaps;
 8 
 9 int m, n;
10 int cnt = 1;
11 int a[200010];
12 
13 int main()
14 {
15     cin >> m >> n;
16     for (int i = 1; i <= m; i++)
17     {
18         cin >> a[i];
19     }
20     for (int i = 1; i <= n; i++)
21     {
22         int t;
23         cin >> t;
24         for (; cnt <= t; cnt++)
25         {
26             heaps.push(a[cnt]);
27             int t1, t2;
28             if (!heapb.empty() && (t1 = heapb.top()) > (t2 = heaps.top()))
29             {
30                 heapb.pop();
31                 heaps.pop();
32                 heapb.push(t2);
33                 heaps.push(t1);
34             }
35         }
36         heapb.push(heaps.top());
37         heaps.pop();
38         cout << heapb.top() << endl;
39     }
40     return 0;
41 }
View Code

 

P1801 黑匣子_NOI导刊2010提高(06)

原文:https://www.cnblogs.com/thjkhdf12/p/11641363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!