原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233
简单题,stl水之。。。
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<set> 6 using std::multiset; 7 struct Node { 8 int val, pos; 9 Node(int _val = 0, int _pos = 0) :val(_val), pos(_pos) {} 10 }; 11 struct cmp { 12 bool operator()(const Node &a, const Node &b) const { 13 if (a.val == b.val) return a.pos < b.pos; 14 return a.val < b.val; 15 } 16 }; 17 multiset<Node,cmp> rec; 18 int main() { 19 #ifdef LOCAL 20 freopen("in.txt", "r", stdin); 21 freopen("out.txt", "w+", stdout); 22 #endif 23 int n, m, v; 24 while (~scanf("%d %d", &n, &m)) { 25 for (int i = 1; i <= n; i++) { 26 scanf("%d", &v); 27 Node t(v, i); 28 rec.insert(t); 29 } 30 while (m--) { 31 scanf("%d", &v); 32 multiset<Node, cmp>::iterator ite = rec.lower_bound(v); 33 if (ite == rec.end() || v < ite->val) puts("-1"); 34 else printf("%d ", ite->pos), rec.erase(ite); 35 } 36 rec.clear(); 37 } 38 return 0; 39 }