【Codeforces 670C】 Cinema
【题目链接】
http://codeforces.com/contest/670/problem/C
【算法】
离散化
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 200010 int n,m,pos,mx = -1,nx = -1,len,i,rkb,rkc; int a[MAXN],b[MAXN],c[MAXN],s[MAXN<<2],tmp[MAXN<<2]; template <typename T> inline void read(T &x) { int f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; } for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= f; } template <typename T> inline void write(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) write(x/10); putchar(x%10+'0'); } template <typename T> inline void writeln(T x) { write(x); puts(""); } int main() { read(n); for (i = 1; i <= n; i++) { read(a[i]); tmp[++len] = a[i]; } read(m); for (i = 1; i <= m; i++) { read(b[i]); tmp[++len] = b[i]; } for (i = 1; i <= m; i++) { read(c[i]); tmp[++len] = c[i]; } sort(tmp+1,tmp+n+2*m+1); len = unique(tmp+1,tmp+n+2*m+1) - tmp; for (i = 1; i <= n; i++) s[lower_bound(tmp+1,tmp+len+1,a[i])-tmp]++; for (i = 1; i <= m; i++) { rkb = lower_bound(tmp+1,tmp+len+1,b[i]) - tmp; rkc = lower_bound(tmp+1,tmp+len+1,c[i]) - tmp; if (s[rkb] > mx) { pos = i; mx = s[rkb]; nx = s[rkc]; } else if (s[rkb] == mx && s[rkc] > nx) { pos = i; nx = s[rkc]; } } writeln(pos); return 0; }