Minimum Maximum and maximum minimum
(0327)Time limit (MS): 2500 memory limit (Kb): 65535 submission: 329 accepted: 18 Description
It is also a data processing question (>_< ). Let's look at the input directly.
Input
A group of test instances. Line 1: two numbers n, m (1 <= n <= 1000000, 1 <= m <= 100000), N indicates the number of numbers, and M indicates the number of queries. Line 2: contains N integers A (I) (0 <= a (I) <= 1000000000 ). Separate Two numbers with spaces. Next m rows: each row contains two integers, A and B (1 <= A <= 2,-1000000000 <= B <= 1000000000 ). Indicates a query. When a = 1, the maximum number of N numbers smaller than B is output. When a = 2, the minimum value of N numbers greater than B is output. If there is no number that meets the condition,-1 is output.
Output
Each query outputs an answer. Each answer occupies one row.
Sample Input
Sample output
Hintscpc_zhangjian
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define INF 0x7fffffff # define n 1000010 int n, m; int A [n]; int low_bound (int K) {int L = 1, R = n + 1; while (L <R) {int M = L + (R-l)/2; if (a [m]> = k) r = m; else l = m + 1;} return l ;} int up_bound (int K) {int L = 1, R = n + 1; while (L <r) {int M = L + (R-l)/2; if (A [m] <= k) L = m + 1; else r = m;} return l;} int main () {int I, j, X; scanf ("% d", & N, & M); for (I = 1; I <= N; I ++) {scanf ("% d ", & A [I]);} Sort (a + 1, A + n + 1 ); // tease ratio, unordered, always wa, cannot stand = while (M --) {int op, X; scanf ("% d", & OP, & X); If (OP = 1 & A [1]> = x | op = 2 & A [n] <= X) {cout <-1 <Endl; continue;} If (OP = 1) {int ans = low_bound (x); ans --; cout <A [ANS] <Endl;} else {int ans = up_bound (x); cout <A [ANS] <Endl ;}} return 0 ;}
Binary [swust OJ 327] minimum maximum and maximum minimum