結果

問題 No.230 Splarraay スプラレェーイ
ユーザー eitahoeitaho
提出日時 2016-03-23 18:19:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,741 ms / 5,000 ms
コード長 4,838 bytes
コンパイル時間 3,622 ms
コンパイル使用メモリ 117,396 KB
実行使用メモリ 27,776 KB
最終ジャッジ日時 2024-10-01 21:36:53
合計ジャッジ時間 9,617 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0