1. 程式人生 > >HDU 5360: Hiking

HDU 5360: Hiking

esp int back amp cout spa typedef size round

Hiking

[email protected] Sycamore, ZJNU;
[email protected] 8/4/2017
#include<bits/stdc++.h>
using namespace std;
#define endl ‘\n‘
typedef long long ll;
struct soda
{
	int l, r, id;
};
struct _1st
{
	bool operator() (const soda &x, const soda &y)
	{
		if (x.l != y.l) return
x.l>y.l; if (x.r != y.r)return x.r<y.r; return x.id<y.id; } }; struct _2nd { bool operator()(const soda &x, const soda &y) { if (x.r != y.r)return x.r>y.r; if (x.l != y.l) return x.l>y.l; return x.id<y.id; } }; int main() { ios::sync_with_stdio(false); //cin.tie(0);
int t; cin >> t; while (t--) { int n; cin >> n; vector<soda>v(n); vector<queue<soda>>s(n + 1); for (int i = 0; i<n; i++) { cin >> v[i].l; } for (int i = 0; i<n; i++) { v[i].id = i + 1; cin >> v[i].r; s[v[i].l].push(v[i]
); } int now; priority_queue<soda, vector<soda>, _2nd>pq; queue<int>ans; int cnt = 0; for (now = 0; now <= n; ) { while (!s[now].empty()) { pq.push(s[now].front()); s[now].pop(); } if (!pq.empty()) { if (pq.top().r >= now) { cnt++; ans.push(pq.top().id); pq.pop(); now++; } else { ans.push(pq.top().id); pq.pop(); } } else { for (auto &e : s) { while (!e.empty()) { ans.push(e.front().id); e.pop(); } } break; } if (now == n) { for (auto &e : s) { while (!e.empty()) { ans.push(e.front().id); e.pop(); } } while (!pq.empty()) { ans.push(pq.top().id); pq.pop(); } } } cout << cnt << endl; bool f = true; while (!ans.empty()) { if (!f)cout << ‘ ‘; else f = false; cout << ans.front(); ans.pop(); } cout << endl; } return 0; }

HDU 5360: Hiking