結果

問題 No.230 Splarraay スプラレェーイ
ユーザー eitahoeitaho
提出日時 2016-03-23 18:19:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,949 ms / 5,000 ms
コード長 4,838 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 116,940 KB
実行使用メモリ 35,804 KB
最終ジャッジ日時 2024-04-09 21:09:55
合計ジャッジ時間 9,435 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,980 KB
testcase_01 AC 28 ms
25,244 KB
testcase_02 AC 28 ms
25,372 KB
testcase_03 AC 28 ms
27,196 KB
testcase_04 AC 28 ms
25,144 KB
testcase_05 AC 28 ms
23,092 KB
testcase_06 AC 37 ms
29,420 KB
testcase_07 AC 30 ms
25,116 KB
testcase_08 AC 31 ms
23,088 KB
testcase_09 AC 177 ms
31,192 KB
testcase_10 AC 130 ms
31,452 KB
testcase_11 AC 88 ms
32,032 KB
testcase_12 AC 169 ms
32,972 KB
testcase_13 AC 40 ms
27,264 KB
testcase_14 AC 1,949 ms
31,964 KB
testcase_15 AC 1,361 ms
33,888 KB
testcase_16 AC 1,076 ms
31,704 KB
testcase_17 AC 461 ms
35,804 KB
testcase_18 AC 1,100 ms
33,496 KB
testcase_19 AC 218 ms
30,972 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.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);
        long[] A = new long[N / 64 + 1];
        long[] B = new long[N / 64 + 1];
        long scoreA = 0, scoreB = 0;

        foreach (var q in Qs)
        {
            if (q[0] == 0)
            {
                long countA = BitArrayCount(A, q[1], q[2] + 1);
                long countB = BitArrayCount(B, q[1], q[2] + 1);
                if (countA > countB) scoreA += countA;
                if (countB > countA) scoreB += countB;
            }
            else if (q[0] == 1)
            {
                BitArrayOr(A, q[1], q[2] + 1);
                BitArrayClear(B, q[1], q[2] + 1);
            }
            else
            {
                BitArrayOr(B, q[1], q[2] + 1);
                BitArrayClear(A, q[1], q[2] + 1);
            }
        }
        scoreA += BitArrayCount(A, 0, N);
        scoreB += BitArrayCount(B, 0, N);

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

    // [L, R)
    static void BitArrayOr(long[] A, int L, int R)
    {
        if (L >= R) return;
        int Li = L >> 6;
        if (Li == (R - 1 >> 6))
        {
            if (R - L == 64) A[Li] |= -1L;
            else A[Li] |= (1L << R - L) - 1 << L;
            return;
        }
        int Ri = R >> 6;
        if ((L & 63) == 0) A[Li] |= -1L;
        else A[Li] |= (1L << 64 - L) - 1 << L;
        for (int i = Li + 1; i < Ri; i++) A[i] = -1L;
        A[Ri] |= (1L << R) - 1;
    }

    // [L, R)
    static void BitArrayClear(long[] A, int L, int R)
    {
        if (L >= R) return;
        int Li = L >> 6;
        if (Li == (R - 1 >> 6))
        {
            if (R - L == 64) A[Li] = 0;
            else A[Li] &= ~((1L << R - L) - 1 << L);
            return;
        }
        int Ri = R >> 6;
        if ((L & 63) == 0) A[Li] = 0;
        else A[Li] &= ~((1L << 64 - L) - 1 << L);
        for (int i = Li + 1; i < Ri; i++) A[i] = 0;
        A[Ri] &= ~((1L << R) - 1);
    }

    // [L, R)
    private long BitArrayCount(long[] A, int L, int R)
    {
        if (L >= R) return 0;
        int Li = L >> 6;
        if (Li == (R - 1 >> 6))
        {
            if (R - L == 64) return BitCount64(A[Li]);
            else return BitCount64(A[Li] >> L & (1L << R - L) - 1);
        }
        long count = 0;
        int Ri = R >> 6;
        if ((L & 63) == 0) count = BitCount64(A[Li]);
        else count = BitCount64(A[Li] >> L & (1L << 64 - L) - 1);
        for (int i = Li + 1; i < Ri; i++) count += BitCount64(A[i]);
        count += BitCount64(A[Ri] & (1L << R) - 1);
        return count;
    }
    static long BitCount64(long x)
    {
        x -= x >> 1 & 0x5555555555555555;
        x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
        return (x + (x >> 4) & 0x0f0f0f0f0f0f0f0f) * 0x0101010101010101 >> 56;
    }
}

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 => Next()).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