标签:
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 724 Accepted Submission(s): 384
Special Judge
水题,先按li排序,然后不断地塞进优先队列
1 /** 2 * code generated by JHelper 3 * More info: https://github.com/AlexeyDmitriev/JHelper 4 * @author xyiyy @https://github.com/xyiyy 5 */ 6 7 #include <iostream> 8 #include <fstream> 9 10 //##################### 11 //Author:fraud 12 //Blog: http://www.cnblogs.com/fraud/ 13 //##################### 14 //#pragma comment(linker, "/STACK:102400000,102400000") 15 #include <iostream> 16 #include <sstream> 17 #include <ios> 18 #include <iomanip> 19 #include <functional> 20 #include <algorithm> 21 #include <vector> 22 #include <string> 23 #include <list> 24 #include <queue> 25 #include <deque> 26 #include <stack> 27 #include <set> 28 #include <map> 29 #include <cstdio> 30 #include <cstdlib> 31 #include <cmath> 32 #include <cstring> 33 #include <climits> 34 #include <cctype> 35 36 using namespace std; 37 #define mp(X, Y) make_pair(X,Y) 38 #define pb(X) push_back(X) 39 #define rep(X, N) for(int X=0;X<N;X++) 40 #define rep2(X, L, R) for(int X=L;X<=R;X++) 41 typedef pair<int, int> PII; 42 43 typedef pair<PII, int> PIII; 44 priority_queue<PIII, vector<PIII>, greater<PIII> > q; 45 int f[100010]; 46 int l[100010]; 47 int r[100010]; 48 vector<int> v[100010]; 49 50 class hdu5360 { 51 public: 52 void solve(std::istream &in, std::ostream &out) { 53 int n; 54 in >> n; 55 for (int i = 1; i <= n; i++)in >> l[i]; 56 for (int i = 1; i <= n; i++) { 57 in >> r[i]; 58 if (l[i])v[l[i]].pb(i); 59 else q.push(mp(mp(r[i], l[i]), i)); 60 } 61 int num = n; 62 int ans = 0; 63 int sz = 0; 64 while (n) { 65 if (q.empty()) { 66 rep2(i, ans + 1, n) { 67 rep(j, v[i].size()) { 68 f[sz++] = v[i][j]; 69 } 70 v[i].clear(); 71 } 72 break; 73 } 74 PIII p = q.top(); 75 q.pop(); 76 int y = p.first.first; 77 int x = p.first.second; 78 int z = p.second; 79 f[sz++] = z; 80 if (x <= ans && y >= ans) { 81 ans++; 82 rep(i, v[ans].size()) { 83 int j = v[ans][i]; 84 q.push(mp(mp(r[j], l[j]), j)); 85 } 86 v[ans].clear(); 87 } 88 } 89 out << ans << endl; 90 rep(i, sz) { 91 if (i)out << " "; 92 out << f[i]; 93 } 94 out << endl; 95 } 96 }; 97 98 int main() { 99 std::ios::sync_with_stdio(false); 100 std::cin.tie(0); 101 hdu5360 solver; 102 std::istream &in(std::cin); 103 std::ostream &out(std::cout); 104 int n; 105 in >> n; 106 for (int i = 0; i < n; ++i) { 107 solver.solve(in, out); 108 } 109 110 return 0; 111 }
标签:
原文地址:http://www.cnblogs.com/fraud/p/4712125.html