結果

問題 No.60 魔法少女
ユーザー yupiteru_kunyupiteru_kun
提出日時 2020-03-16 20:19:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 701 ms / 5,000 ms
コード長 8,903 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 118,068 KB
実行使用メモリ 135,448 KB
最終ジャッジ日時 2023-08-18 19:25:43
合計ジャッジ時間 9,930 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
56,748 KB
testcase_01 AC 85 ms
68,324 KB
testcase_02 AC 87 ms
69,716 KB
testcase_03 AC 88 ms
68,440 KB
testcase_04 AC 432 ms
129,564 KB
testcase_05 AC 550 ms
129,796 KB
testcase_06 AC 686 ms
135,448 KB
testcase_07 AC 538 ms
126,436 KB
testcase_08 AC 433 ms
135,440 KB
testcase_09 AC 262 ms
114,212 KB
testcase_10 AC 667 ms
117,384 KB
testcase_11 AC 180 ms
85,944 KB
testcase_12 AC 426 ms
107,712 KB
testcase_13 AC 701 ms
117,392 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class YUKICODER1
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var K = NN;
            var XYHP = Repeat(0, N).Select(_ => new { X = NN, Y = NN, HP = NN }).ToArray();
            var AXAYWHD = Repeat(0, K).Select(_ => new { AX = NN, AY = NN, W = NN, H = NN, D = NN }).ToArray();
            var seg = new LIB_DualSegTree2D<long>(1501, 1501, 0, (x, y) => x + y);
            foreach (var item in AXAYWHD)
            {
                seg.Update(item.AX + 500, item.AX + 500 + item.W + 1, item.AY + 500, item.AY + 500 + item.H + 1, item.D);
            }
            var ans = 0L;
            foreach (var item in XYHP)
            {
                var dam = seg[item.X + 500, item.Y + 500];
                ans += Max(0, item.HP - dam);
            }
            Console.WriteLine(ans);
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_DualSegTree2D<T> where T : IEquatable<T>
    {
        int xsz;
        int ysz;
        T ti;
        Func<T, T, T> f;
        T[,] dat;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_DualSegTree2D(long _xsz, long _ysz, T _ti, Func<T, T, T> _f)
        {
            xsz = 1; ysz = 1;
            while (xsz < _xsz) xsz <<= 1;
            while (ysz < _ysz) ysz <<= 1;
            ti = _ti;
            f = _f;
            dat = new T[xsz << 1, ysz << 1];
            for (var i = 0; i < xsz; ++i) for (var j = 0; j < ysz; ++j) dat[i, j] = ti;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Update(long xl, long xr, long yl, long yr, T v)
        {
            if (xl == xr || yl == yr) return;
            if (xr < xl || yr < yl) throw new Exception();
            for (long xli = xsz + xl, xri = xsz + xr; xli < xri; xli >>= 1, xri >>= 1)
            {
                if ((xli & 1) == 1)
                {
                    for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1)
                    {
                        if ((yli & 1) == 1) { dat[xli, yli] = f(dat[xli, yli], v); ++yli; }
                        if ((yri & 1) == 1) { --yri; dat[xli, yri] = f(dat[xli, yri], v); }
                    }
                    ++xli;
                }
                if ((xri & 1) == 1)
                {
                    --xri;
                    for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1)
                    {
                        if ((yli & 1) == 1) { dat[xri, yli] = f(dat[xri, yli], v); ++yli; }
                        if ((yri & 1) == 1) { --yri; dat[xri, yri] = f(dat[xri, yri], v); }
                    }
                }
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void EvalY(long x, long y)
        {
            if (y < 1) return;
            EvalY(x, y >> 1);
            if (dat[x, y].Equals(ti)) return;
            if (y < ysz)
            {
                dat[x, (y << 1) | 0] = f(dat[x, (y << 1) | 0], dat[x, y]);
                dat[x, (y << 1) | 1] = f(dat[x, (y << 1) | 1], dat[x, y]);
                dat[x, y] = ti;
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void EvalXY(long x, long y)
        {
            if (x < 1) return;
            EvalXY(x >> 1, y);
            EvalY(x, y);
            if (dat[x, y].Equals(ti)) return;
            if (x < xsz)
            {
                dat[(x << 1) | 0, y] = f(dat[(x << 1) | 0, y], dat[x, y]);
                dat[(x << 1) | 1, y] = f(dat[(x << 1) | 1, y], dat[x, y]);
                dat[x, y] = ti;
            }
        }
        public T this[long x, long y]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get { EvalXY(x += xsz, y += ysz); return dat[x, y]; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            set { EvalXY(x += xsz, y += ysz); dat[x, y] = value; }
        }
    }
    class LIB_FastIO
    {
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        public LIB_FastIODebug() { }
        public override string Scan() => NextString();
        public override long Long() => long.Parse(NextString());
        public override double Double() => double.Parse(NextString());
    }
}
0