Codeforces 670C Cinema

题目链接

题解

对于每一个影片分别统计一下看的很满意的人和比较满意的人数,维护答案即可。
数据很大,需要离散化一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
int f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar(); }
while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return f * x;
}
int n, m, a[200005], b[200005], c[200005];
void init(){
n = read();
for(int i = 0; i < n; ++i)
a[i] = read();
m = read();
for(int i = 0; i < m; ++i)
b[i] = read();
for(int i = 0; i < m; ++i)
c[i] = read();
}
void solve(){
sort(a, a + n);
int max1 = 0, max2 = 0, ans = 1;
for(int i = 0; i < m; ++i){
int r1 = upper_bound(a, a + n, b[i]) - lower_bound(a, a + n, b[i]);
int r2 = upper_bound(a, a + n, c[i]) - lower_bound(a, a + n, c[i]);
if(r1 > max1)
max1 = r1, max2 = r2, ans = i + 1;
else if(r1 == max1 && r2 > max2)
max2 = r2, ans = i + 1;
}
printf("%d\n", ans);
}
int main(){
init();
solve();
return 0;
}