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

 1 #include
 2 #include
 3 #include
 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))