結果

問題 No.230 Splarraay スプラレェーイ
ユーザー くれちーくれちー
提出日時 2017-07-20 15:57:23
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 5,825 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 118,600 KB
実行使用メモリ 55,920 KB
最終ジャッジ日時 2024-10-08 17:44:47
合計ジャッジ時間 5,255 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
18,176 KB
testcase_01 RE -
testcase_02 AC 25 ms
18,176 KB
testcase_03 AC 25 ms
18,176 KB
testcase_04 AC 25 ms
18,176 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input;

    public IO(TextReader reader)
    {
        input = reader.ReadToEnd().Split(new[] { " ", Environment.NewLine },
            StringSplitOptions.RemoveEmptyEntries);
    }

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
#if !DEBUG
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
#endif
        Solve(new IO(In));
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var m = io.I;

        var s = (int)Ceiling(Sqrt(n));
        var arr = new bool?[n];
        var baq = new bool?[s];
        var baqlen = n / s + (n % s == 0 ? 0 : 1);
        var ap = 0;
        var bp = 0;

        for (var _ = 0; _ < m; _++)
        {
            var q = io.I;
            var l = io.I;
            var r = io.I;

            var baqli = l / s + (l % s == 0 ? 0 : 1);
            var baqri = (r + 1) / s - 1;
            if (r == n - 1) baqri = baqlen - 1;

            if (q == 0)
            {
                var tap = 0;
                var tbp = 0;

                for (var i = baqli; i <= baqri; i++)
                {
                    if (baq[i] == null)
                    {
                        var ol = i * s;
                        var or = ol + s - 1;

                        for (var j = ol; j <= or; j++)
                        {
                            if (!arr[j].HasValue) continue;
                            if (arr[j].Value) tap++;
                            else tbp++;
                        }
                    }
                    else if (baq[i].Value) tap += s;
                    else tbp += s;
                }

                if (baqli > baqri)
                {
                    for (var i = l; i <= r; i++)
                    {
                        if (!arr[i].HasValue) continue;
                        if (arr[i].Value) tap++;
                        else tbp++;
                    }

                    goto Count;
                }

                if (l % s != 0)
                {
                    var olr = Min(n - 1, (l / s + (l % s == 0 ? 0 : 1)) * s - 1);

                    for (var i = l; i <= olr; i++)
                    {
                        if (!arr[i].HasValue) continue;
                        if (arr[i].Value) tap++;
                        else tbp++;
                    }
                }
                if ((r + 1) % s != 0)
                {
                    var orl = (r + 1) / s * s;

                    for (var i = orl; i <= r; i++)
                    {
                        if (!arr[i].HasValue) continue;
                        if (arr[i].Value) tap++;
                        else tbp++;
                    }
                }

                Count:
                if (tap > tbp) ap += tap;
                if (tap < tbp) bp += tbp;

                continue;
            }

            for (var i = baqli; i <= baqri; i++) baq[i] = q == 1;

            if (l % s != 0)
            {
                if (baq[baqli - 1] != null)
                {
                    var ol = (baqli - 1) * s;
                    var or = Min(n - 1, ol + s - 1);
                    for (var i = ol; i <= or; i++) arr[i] = baq[baqli - 1].Value;
                    baq[baqli - 1] = null;
                }

                var olr = Min(n - 1, (l / s + (l % s == 0 ? 0 : 1)) * s - 1);
                for (var i = l; i <= olr; i++) arr[i] = q == 1;
            }
            if ((r + 1) % s != 0)
            {
                if (baq[baqri + 1] != null)
                {
                    var ol = (baqri + 1) * s;
                    var or = Min(n - 1, ol + s - 1);
                    for (var i = ol; i <= or; i++) arr[i] = baq[baqri + 1].Value;
                    baq[baqri + 1] = null;
                }

                var orl = (r + 1) / s * s;
                for (var i = orl; i <= r; i++) arr[i] = q == 1;
            }
        }

        for (var i = 0; i < baqlen; i++)
        {
            if (baq[i] == null)
            {
                var ol = i * s;
                var or = Min(n - 1, ol + s - 1);

                for (var j = ol; j <= or; j++)
                {
                    if (!arr[j].HasValue) continue;
                    if (arr[j].Value) ap++;
                    else bp++;
                }
            }
            else if (baq[i].Value) ap += s;
            else bp += i == baqlen - 1 ? n - s * (baqlen - 1) : s;
        }

        io.Write(ap, bp);
    }
}
0