Gunner II
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1433 Accepted Submission (s): 540
Problem Descriptionlong long ago, there was a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There is n birds and n trees. The i-th bird stands on the top of the i-th tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the most tree. When Jack shots a bullet inch height h to the right, the nearest bird which stands in the tree with height H'll falls.
Jack would shot many times, he wants to know which bird would fall during each shot.
Inputthere is multiple test cases (about 5), every case gives N, m on the first line, n indicates there is n trees and N Birds, m means Jack would shot m times.
In the second line, there is n numbers h[1],h[2],h[3],..., H[n] which describes the height of the trees.
In the third line, there is m numbers q[1],q[2],q[3],..., Q[m] which describes the height of the Jack ' s shots.
Please process to the end of file.
[Technical specification]
All input items is integers.
1<=n,m<=100000 (10^5)
1<=h[i],q[i]<=1000000000 (10^9)
Outputfor each q[i], output an integer in a single line indicates the ID of bird Jack shots down. If Jack can ' t shot any bird, just output-1.
The ID starts from 1.
Sample INPUT5 51 2 3 4 11 3 1 4 2
Sample Output13542
HintHuge input, Fast IO is recommended.
Sourcebestcoder Round #42 because there are only 1E5 of the data, and the height of 1E9 so consider discretization about the content of discretization, this blog is very good. http://blog.csdn.net/axuan_k/article/details/45954561 I was using the third method of Map+set ... Discretization is probably because the data is too large to be stored in the table ... Then the map key value has no range? So the discretization is realized (is that so??? )
/************************************************************************* > File name:code/bc/#42/b.cpp > AUTHOR:111QQZ > Email: [email protected] > Created time:2015 August 01 Saturday 02:47 54 Seconds ************************ ************************************************/#include<iostream>#include<iomanip>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#defineY0 ABC111QQZ#defineY1 HUST111QQZ#defineYn hez111qqz#defineJ1 CUTE111QQZ#defineTM CRAZY111QQZ#defineLR DYING111QQZusing namespacestd;#defineREP (i, n) for (int i=0;i<int (n); ++i)typedefLong Longll;typedef unsignedLong LongULL;Const intINF =0x7fffffff;Const intn=2e5+7;intN,m;map<int,int>CPUSet<int>Se[n];intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) { for(inti =1; I <= N; i++) se[i].clear (); Mp.clear (); intt =0; intx; for(inti =1; I <= N; i++) {scanf ("%d",&x); if(!mp[x]) mp[x]=++T; Se[mp[x]].insert (i); } for(inti =1; I <= m; i++) {scanf ("%d",&x); if(se[mp[x]].size () = =0) {puts ("-1"); } Else{printf ("%d\n",*Se[mp[x]].begin ()); Se[mp[x]].erase (Se[mp[x]].begin ()); } } } return 0;}
HDU 5233 Gunner II (BC #42 B)