結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー 👑 kakel-sankakel-san
提出日時 2023-08-03 21:33:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 3,276 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 117,616 KB
実行使用メモリ 61,132 KB
最終ジャッジ日時 2024-04-21 20:02:04
合計ジャッジ時間 18,129 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
18,944 KB
testcase_01 AC 279 ms
48,136 KB
testcase_02 AC 306 ms
58,520 KB
testcase_03 AC 291 ms
53,452 KB
testcase_04 AC 296 ms
55,984 KB
testcase_05 AC 300 ms
57,032 KB
testcase_06 AC 315 ms
52,612 KB
testcase_07 AC 313 ms
53,588 KB
testcase_08 AC 317 ms
56,672 KB
testcase_09 AC 322 ms
61,132 KB
testcase_10 AC 301 ms
59,488 KB
testcase_11 AC 321 ms
59,420 KB
testcase_12 AC 318 ms
59,544 KB
testcase_13 AC 318 ms
59,292 KB
testcase_14 AC 316 ms
59,400 KB
testcase_15 AC 313 ms
59,152 KB
testcase_16 AC 319 ms
59,548 KB
testcase_17 AC 319 ms
59,024 KB
testcase_18 AC 314 ms
59,268 KB
testcase_19 AC 316 ms
59,164 KB
testcase_20 AC 317 ms
59,396 KB
testcase_21 AC 344 ms
59,716 KB
testcase_22 AC 346 ms
59,464 KB
testcase_23 AC 345 ms
59,708 KB
testcase_24 AC 347 ms
59,712 KB
testcase_25 AC 348 ms
59,468 KB
testcase_26 AC 347 ms
59,600 KB
testcase_27 AC 344 ms
59,336 KB
testcase_28 AC 347 ms
59,464 KB
testcase_29 AC 350 ms
59,728 KB
testcase_30 AC 347 ms
59,604 KB
testcase_31 AC 261 ms
57,852 KB
testcase_32 AC 257 ms
57,500 KB
testcase_33 AC 259 ms
57,492 KB
testcase_34 AC 274 ms
58,024 KB
testcase_35 AC 293 ms
58,132 KB
testcase_36 AC 269 ms
58,020 KB
testcase_37 AC 50 ms
23,140 KB
testcase_38 AC 311 ms
58,836 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 static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new string[t];
        for (var u = 0; u < t; ++u)
        {
            var n = NN;
            var x = ReadLine().Split();
            var y = ReadLine().Split();
            var s = NList;
            ans[u] = IsTrue(n, x, y, s);
        }
        WriteLine(string.Join("\n", ans));
    }
    static string IsTrue(int n, string[] x, string[] y, int[] s)
    {
        var xl = new int[x.Length];
        for (var i = 0; i < xl.Length; ++i) xl[i] = x[i] == "False" ? 0 : 1;
        var yl = new int[y.Length];
        for (var i = 0; i < yl.Length; ++i) yl[i] = Decode(y[i]);
        var ft = new FenwickTree(n);
        for (var i = 0; i < n; ++i) ft.Add(i, 1);
        foreach (var si in s)
        {
            var pos0 = ft.LowerBound(si);
            var pos1 = ft.LowerBound(si + 1);
            xl[pos1] = Calc(xl[pos0], xl[pos1], yl[pos0]);
            ft.Add(pos0, -1);
        }
        return xl[ft.LowerBound(1)] == 0 ? "False" : "True";
    }
    static int Decode(string s)
    {
        switch (s)
        {
            case "and": return 0;
            case "or" : return 1;
            case "xor": return 2;
            default: return 3;
        }
    }
    static int Calc(int a, int b, int op)
    {
        switch (op)
        {
            case 0: return a & b;
            case 1: return a | b;
            case 2: return a ^ b;
            default: return 1 - a | b;
        }
    }
    class FenwickTree
    {
        int size;
        long[] tree;
        public FenwickTree(int size)
        {
            this.size = size;
            tree = new long[size + 2];
        }
        public void Add(int index, int value)
        {
            ++index;
            for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
        }
        /// <summary>先頭からindexまでの和(include index)</summary>
        public long Sum(int index)
        {
            ++index;
            var sum = 0L;
            for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
            return sum;
        }
        /// <summary>Sum(x) >= value となる最小のxを求める</summary>
        // 各要素は非負であること
        public int LowerBound(long value)
        {
            if (value < 0) return -1;
            var x = 0;
            var b = 1;
            while (b * 2 <= size) b <<= 1;
            for (var k = b; k > 0; k >>= 1)
            {
                if (x + k <= size && tree[x + k] < value)
                {
                    value -= tree[x + k];
                    x += k;
                }
            }
            return x;
        }
    }
}
0