예제 #1
0
    static void Main()
    {
        var z = Read();
        int h = z[0], w = z[1], n = z[2], m = z[3];
        var abs = Array.ConvertAll(new bool[n], _ => Read().Select(v => v - 1).ToArray());
        var cds = Array.ConvertAll(new bool[m], _ => Read().Select(v => v - 1).ToArray());

        var a = new bool[h, w];

        foreach (var p in cds)
        {
            a[p[0], p[1]] = true;
        }

        var rh = Enumerable.Range(0, h).ToArray();
        var rw = Enumerable.Range(0, w).ToArray();

        var bRow = rh.Select(i => rw.Where(j => a[i, j]).ToArray()).ToArray();
        var bCol = rw.Select(j => rh.Where(i => a[i, j]).ToArray()).ToArray();

        var raq = new StaticRAQ2(h, w);

        foreach (var p in abs)
        {
            var r = bRow[p[0]];
            var c = bCol[p[1]];

            var j = First(0, r.Length, x => r[x] > p[1]);
            raq.Add(p[0], j == 0 ? 0 : r[j - 1] + 1, p[0] + 1, j == r.Length ? w : r[j], 1);

            var i = First(0, c.Length, x => c[x] > p[0]);
            raq.Add(i == 0 ? 0 : c[i - 1] + 1, p[1], i == c.Length ? h : c[i], p[1] + 1, 1);
        }

        var d   = raq.GetAll0();
        var sum = 0;

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (d[i, j] > 0)
                {
                    sum++;
                }
            }
        }
        Console.WriteLine(sum);
    }
예제 #2
0
    static object Solve()
    {
        var(n, k) = Read2();
        var a = Array.ConvertAll(new bool[n], _ => Read());

        return(Last(0, a.Max(r => r.Max()), m =>
        {
            var raq = new StaticRAQ2(n, n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    raq.Add(i, j, i + k, j + k, a[i][j] >= m ? 1 : -1);
                }
            }

            var all = raq.GetAll0();

            for (int i = k - 1; i < n; i++)
            {
                for (int j = k - 1; j < n; j++)
                {
                    if (all[i, j] <= 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }));
    }
예제 #3
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var rs = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        var xs = rs.Select(r => r[0]).Concat(rs.Select(r => r[2])).Distinct().OrderBy(v => v).ToArray();
        var xd = Enumerable.Range(0, xs.Length).ToDictionary(i => xs[i]);
        var ys = rs.Select(r => r[1]).Concat(rs.Select(r => r[3])).Distinct().OrderBy(v => v).ToArray();
        var yd = Enumerable.Range(0, ys.Length).ToDictionary(i => ys[i]);

        var raq = new StaticRAQ2(xs.Length, ys.Length);

        foreach (var r in rs)
        {
            raq.Add(xd[r[0]], yd[r[1]], xd[r[2]], yd[r[3]], 1);
        }
        var s = raq.GetAll();

        var sum = 0L;

        for (int i = 0; i < xs.Length; i++)
        {
            for (int j = 0; j < ys.Length; j++)
            {
                if (s[i, j] > 0)
                {
                    sum += (long)(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
                }
            }
        }
        Console.WriteLine(sum);
    }
예제 #4
0
	static object Solve()
	{
		var n = int.Parse(Console.ReadLine());
		var ps = Array.ConvertAll(new bool[n], _ => Read4());

		var raq = new StaticRAQ2(h, w);
		foreach (var (lx, ly, rx, ry) in ps)
		{
			raq.Add(lx, ly, rx, ry, 1);
		}
		var all = raq.GetAll0();

		var r = new int[n];
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (all[i, j] == 0) continue;
				r[all[i, j] - 1]++;
			}
		}
		return string.Join("\n", r);
	}
예제 #5
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var rs = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        var raq = new StaticRAQ2(1000, 1000);

        foreach (var r in rs)
        {
            raq.Add(r[0], r[1], r[2], r[3], 1);
        }
        var s = raq.GetAll();

        var M = 0L;

        for (int i = 0; i < 1000; i++)
        {
            for (int j = 0; j < 1000; j++)
            {
                M = Math.Max(M, s[i, j]);
            }
        }
        Console.WriteLine(M);
    }
예제 #6
0
    static object Solve()
    {
        var(n, k) = Read2();
        var ps = Array.ConvertAll(new bool[n], _ => Read2());

        var raq = new StaticRAQ2(max + 1, max + 1);

        foreach (var(a, b) in ps)
        {
            raq.Add(a, b, a + k + 1, b + k + 1, 1);
        }
        var all = raq.GetAll0();

        var r = 0L;

        for (int i = 0; i <= max; i++)
        {
            for (int j = 0; j <= max; j++)
            {
                r = Math.Max(r, all[i, j]);
            }
        }
        return(r);
    }
예제 #7
0
    static void Main()
    {
        var z = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int h = z[0], w = z[1];
        var s = new int[h].Select(_ => Console.ReadLine()).ToArray();

        var k  = s.Sum(t => t.Count(c => c == '.'));
        var p2 = new long[k + 1];

        p2[0] = 1;
        for (int i = 0; i < k; ++i)
        {
            p2[i + 1] = p2[i] * 2 % M;
        }

        var raq = new StaticRAQ2(h, w);

        raq.Add(0, 0, h, w, -1);

        for (int i = 0; i < h; i++)
        {
            var start = -1;
            for (int j = 0; j <= w; j++)
            {
                if (j < w && s[i][j] == '.')
                {
                    if (start == -1)
                    {
                        start = j;
                    }
                }
                else
                {
                    if (start != -1)
                    {
                        raq.Add(i, start, i + 1, j, j - start);
                    }
                    start = -1;
                }
            }
        }
        for (int j = 0; j < w; j++)
        {
            var start = -1;
            for (int i = 0; i <= h; i++)
            {
                if (i < h && s[i][j] == '.')
                {
                    if (start == -1)
                    {
                        start = i;
                    }
                }
                else
                {
                    if (start != -1)
                    {
                        raq.Add(start, j, i, j + 1, i - start);
                    }
                    start = -1;
                }
            }
        }
        var sum = raq.GetAll();

        var r = 0L;

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (sum[i, j] == -1)
                {
                    continue;
                }
                r = (r + (p2[sum[i, j]] - 1 + M) % M * p2[k - sum[i, j]]) % M;
            }
        }
        Console.WriteLine(r);
    }