結果

問題 No.230 Splarraay スプラレェーイ
ユーザー eitahoeitaho
提出日時 2015-06-20 18:50:07
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,696 bytes
コンパイル時間 4,868 ms
コンパイル使用メモリ 110,788 KB
実行使用メモリ 33,304 KB
最終ジャッジ日時 2023-09-21 22:11:40
合計ジャッジ時間 15,316 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,668 KB
testcase_01 AC 59 ms
21,568 KB
testcase_02 AC 60 ms
23,736 KB
testcase_03 AC 60 ms
21,740 KB
testcase_04 AC 60 ms
21,748 KB
testcase_05 AC 61 ms
21,816 KB
testcase_06 AC 75 ms
23,796 KB
testcase_07 AC 61 ms
21,708 KB
testcase_08 AC 64 ms
21,812 KB
testcase_09 AC 203 ms
33,304 KB
testcase_10 AC 226 ms
30,496 KB
testcase_11 AC 136 ms
27,300 KB
testcase_12 AC 207 ms
29,216 KB
testcase_13 AC 82 ms
25,716 KB
testcase_14 AC 193 ms
33,132 KB
testcase_15 AC 281 ms
33,236 KB
testcase_16 AC 298 ms
31,748 KB
testcase_17 AC 369 ms
32,564 KB
testcase_18 TLE -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

class Program
{
    public void Solve()
    {
        int N = Reader.Int(), Q = Reader.Int();
        var Qs = Reader.IntTable(Q);
        var A = new LazySegTree(N);
        var B = new LazySegTree(N);
        long scoreA = 0, scoreB = 0;

        foreach (var q in Qs)
        {
            int L = q[1], R = q[2] + 1;
            if (q[0] == 0)
            {
                int countA = A.Sum(L, R), countB = B.Sum(L, R);
                if (countA > countB) scoreA += countA;
                if (countB > countA) scoreB += countB;
            }
            else if (q[0] == 1)
            {
                A.Update(L, R, 1);
                B.Update(L, R, 0);
            }
            else
            {
                B.Update(L, R, 1);
                A.Update(L, R, 0);
            }
        }

        scoreA += A.Sum(0, N);
        scoreB += B.Sum(0, N);

        Console.WriteLine(scoreA + " " + scoreB);
    }


    class LazySegTree
    {
        public readonly int N;
        private readonly int[] RangeVal;
        private readonly bool[] Flag;

        public LazySegTree(int n)
        {
            for (N = 4; N < n; ) N *= 2;
            RangeVal = new int[N * 2];
            Flag = new bool[N * 2];
        }
        // [L, R)
        public int Sum(int L, int R) { return Sum(0, 0, N, L, R); }
        private int Sum(int i, int currL, int currR, int L, int R)
        {
            if (currL >= R || currR <= L) return 0;
            if (currR - currL == 1) return RangeVal[i];
            if (currL >= L && currR <= R && Flag[i]) return RangeVal[i] * (currR - currL);
            if (Flag[i])
            {
                Flag[i * 2 + 1] = Flag[i * 2 + 2] = true;
                RangeVal[i * 2 + 1] = RangeVal[i * 2 + 2] = RangeVal[i];
            }
            int mid = (currL + currR) / 2;
            int res = Sum(i * 2 + 1, currL, mid, L, R);
            res += Sum(i * 2 + 2, mid, currR, L, R);
            return res;
        }
        // [L, R)
        public void Update(int L, int R, int val) { Update(0, val, 0, N, L, R); }
        private void Update(int i, int val, int currL, int currR, int L, int R)
        {
            if (currL >= R || currR <= L) return;
            if (currL >= L && currR <= R)
            {
                Flag[i] = true;
                RangeVal[i] = val;
                return;
            }
            if (Flag[i] && currR - currL > 1)
            {
                Flag[i * 2 + 1] = Flag[i * 2 + 2] = true;
                RangeVal[i * 2 + 1] = RangeVal[i * 2 + 2] = RangeVal[i];
                Flag[i] = false;
            }
            int mid = (currL + currR) / 2;
            Update(i * 2 + 1, val, currL, mid, L, R);
            Update(i * 2 + 2, val, mid, currR, L, R);
        }
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0