CF 670C Cinema(算競進階習題)
阿新 • • 發佈:2019-03-15
unique ans max ace getch int digi names const
離散化+排序
離散化統計人數就好,本來不難,但是測試點太喪心病狂了。。。CF還是大哥啊
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; inline int lowbit(int x){ return x & (-x); } inline int read(){ int X = 0, w = 0; char ch = 0; while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } inline int gcd(int a, int b){ return a % b ? gcd(b, a % b) : b; } inline int lcm(int a, int b){ return a / gcd(a, b) * b; } template<typename T> inline T max(T x, T y, T z){ return max(max(x, y), z); } template<typename T> inline T min(T x, T y, T z){ return min(min(x, y), z); } template<typename A, typename B, typename C> inline A fpow(A x, B p, C yql){ A ans = 1; for(; p; p >>= 1, x = 1LL * x * x % yql)if(p & 1)ans = 1LL * x * ans % yql; return ans; } const int N = 200005; int a[N], b[N<<2], tot, num[N<<2]; struct Film{ int x, y, cnt1, cnt2, id; bool operator < (const Film &rhs) const { if(cnt1 != rhs.cnt1) return cnt1 > rhs.cnt1; if(cnt2 != rhs.cnt2) return cnt2 > rhs.cnt2; return id < rhs.id; } }film[N]; int main(){ int n = read(); for(int i = 0; i < n; i ++) a[i] = read(), b[++tot] = a[i]; int m = read(); for(int i = 0; i < m; i ++) film[i].x = read(), b[++tot] = film[i].x, film[i].id = i; for(int i = 0; i < m; i ++) film[i].y = read(), b[++tot] = film[i].y; sort(b + 1, b + tot + 1); tot = unique(b + 1, b + tot + 1) - b - 1; for(int i = 0; i < n; i ++){ num[lower_bound(b + 1, b + tot + 1, a[i]) - b] ++; } for(int i = 0; i < m; i ++){ film[i].cnt1 = num[lower_bound(b + 1, b + tot + 1, film[i].x) - b]; film[i].cnt2 = num[lower_bound(b + 1, b + tot + 1, film[i].y) - b]; } sort(film, film + m); printf("%d\n", film[0].id + 1); return 0; }
CF 670C Cinema(算競進階習題)