public static void Solve() { var N = Scanner.Scan <int>(); var cum = new CumulativeSum2D(1005, 1005); for (var i = 0; i < N; i++) { var(lx, ly, rx, ry) = Scanner.Scan <int, int, int, int>(); cum.Add(lx, ly, 1); cum.Add(lx, ry, -1); cum.Add(rx, ly, -1); cum.Add(rx, ry, 1); } var count = new int[N + 1]; for (var i = 0; i <= 1000; i++) { for (var j = 0; j <= 1000; j++) { count[cum.Sum(i, j)]++; } } for (var i = 1; i <= N; i++) { Console.WriteLine(count[i]); } }
public static void Solve() { var(N, K) = Scanner.Scan <int, int>(); const int max = 5000; var cum = new CumulativeSum2D(max + 1, max + 1); for (var i = 0; i < N; i++) { var(a, b) = Scanner.Scan <int, int>(); cum.Add(a, b, 1); } var answer = 0L; for (var i = 0; i + K < max; i++) { for (var j = 0; j + K < max; j++) { answer = Math.Max(answer, cum.Sum(i, j, i + K + 1, j + K + 1)); } } Console.WriteLine(answer); }
public static void Solve() { var(N, K) = Scanner.Scan <int, int>(); var G = new int[N][]; for (var i = 0; i < N; i++) { G[i] = Scanner.ScanEnumerable <int>().ToArray(); } var border = K * K / 2; bool Check(int m) { var cum = new CumulativeSum2D(N, N); for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { if (G[i][j] > m) { cum.Add(i, j, 1); } } } for (var i = 0; i < N - K + 1; i++) { for (var j = 0; j < N - K + 1; j++) { if (cum.Sum(i, j, i + K, j + K) <= border) { return(true); } } } return(false); } const int inf = (int)1e9; var(l, r) = (-1, inf); while (r - l > 1) { var m = (l + r) / 2; if (Check(m)) { r = m; } else { l = m; } } var answer = r; Console.WriteLine(answer); }