結果

問題 No.2421 entersys?
ユーザー 👑 kakel-sankakel-san
提出日時 2023-08-20 20:24:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,055 ms / 3,000 ms
コード長 7,281 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 68,444 KB
実行使用メモリ 148,492 KB
最終ジャッジ日時 2023-08-20 20:25:16
合計ジャッジ時間 30,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
22,864 KB
testcase_01 AC 64 ms
17,008 KB
testcase_02 AC 67 ms
17,792 KB
testcase_03 AC 63 ms
16,940 KB
testcase_04 AC 64 ms
17,008 KB
testcase_05 AC 66 ms
17,668 KB
testcase_06 AC 70 ms
17,484 KB
testcase_07 AC 67 ms
17,388 KB
testcase_08 AC 67 ms
17,664 KB
testcase_09 AC 72 ms
18,380 KB
testcase_10 AC 67 ms
17,188 KB
testcase_11 AC 1,381 ms
115,544 KB
testcase_12 AC 1,411 ms
123,068 KB
testcase_13 AC 1,387 ms
122,292 KB
testcase_14 AC 1,402 ms
122,396 KB
testcase_15 AC 1,421 ms
123,860 KB
testcase_16 AC 1,497 ms
133,652 KB
testcase_17 AC 1,393 ms
136,080 KB
testcase_18 AC 1,429 ms
130,108 KB
testcase_19 AC 1,436 ms
132,512 KB
testcase_20 AC 1,435 ms
132,264 KB
testcase_21 AC 1,251 ms
133,872 KB
testcase_22 AC 1,121 ms
112,216 KB
testcase_23 AC 1,820 ms
146,940 KB
testcase_24 AC 2,055 ms
148,492 KB
testcase_25 AC 1,771 ms
148,196 KB
testcase_26 AC 885 ms
96,440 KB
testcase_27 AC 902 ms
98,904 KB
testcase_28 AC 908 ms
96,092 KB
権限があれば一括ダウンロードができます

ソースコード

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 string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var _map = SList(n);
        var q = NN;
        var _query = SList(q);
        var map = new (string x, int l, int r)[n];
        for (var i = 0; i < n; ++i)
        {
            var s = _map[i].Split();
            map[i] = (s[0], int.Parse(s[1]), int.Parse(s[2]));
        }
        var query = new (int id, string x, int l, int r)[q];
        for (var i = 0; i < q; ++i)
        {
            var s = _query[i].Split();
            var id = int.Parse(s[0]);
            if (id == 1) query[i] = (id, s[1], int.Parse(s[2]), 0);
            else if (id == 2) query[i] = (id, "", int.Parse(s[1]), 0);
            else query[i] = (id, s[1], int.Parse(s[2]), int.Parse(s[3]));
        }
        var allset = new HashSet<int>();
        var dic = new Dictionary<string, HashSet<int>>();
        for (var i = 0; i < map.Length; ++i)
        {
            allset.Add(map[i].l);
            allset.Add(map[i].r + 1);
            if (!dic.ContainsKey(map[i].x)) dic[map[i].x] = new HashSet<int>();
            dic[map[i].x].Add(map[i].l);
            dic[map[i].x].Add(map[i].r + 1);
        }
        for (var i = 0; i < query.Length; ++i)
        {
            if (query[i].id == 1)
            {
                if (!dic.ContainsKey(query[i].x)) dic[query[i].x] = new HashSet<int>();
                dic[query[i].x].Add(query[i].l);
                allset.Add(query[i].l);
            }
            else if (query[i].id == 2)
            {
                allset.Add(query[i].l);
            }
            else
            {
                if (!dic.ContainsKey(query[i].x)) dic[query[i].x] = new HashSet<int>();
                dic[query[i].x].Add(query[i].l);
                dic[query[i].x].Add(query[i].r + 1);
                allset.Add(query[i].l);
                allset.Add(query[i].r + 1);
            }
        }
        var posmap = new Dictionary<string, List<int>>();
        foreach (var kv in dic)
        {
            posmap[kv.Key] = new List<int>(kv.Value);
            posmap[kv.Key].Sort();
        }
        var segmap = new Dictionary<string, LazyAddSumSegmentTree>();
        foreach (var kv in dic) segmap[kv.Key] = new LazyAddSumSegmentTree(Enumerable.Repeat(0, kv.Value.Count).ToArray());
        var alllist = new List<int>(allset);
        alllist.Sort();
        var allseg = new LazyAddSumSegmentTree(Enumerable.Repeat(0, alllist.Count).ToArray());
        for (var i = 0; i < map.Length; ++i)
        {
            var lpos = LowerBound(0, map[i].l, posmap[map[i].x]);
            var rpos = LowerBound(0, map[i].r + 1, posmap[map[i].x]);
            segmap[map[i].x].AddRange(lpos, rpos, 1);
            lpos = LowerBound(0, map[i].l, alllist);
            rpos = LowerBound(0, map[i].r + 1, alllist);
            allseg.AddRange(lpos, rpos, 1);
        }
        var ans = new List<string>();
        for (var i = 0; i < query.Length; ++i)
        {
            if (query[i].id == 1)
            {
                var pos = LowerBound(0, query[i].l, posmap[query[i].x]);
                ans.Add(segmap[query[i].x].Get(pos, pos + 1) == 1 ? "Yes" : "No");
            }
            else if (query[i].id == 2)
            {
                var pos = LowerBound(0, query[i].l, alllist);
                ans.Add(allseg.Get(pos, pos + 1).ToString());
            }
            else
            {
                var lpos = LowerBound(0, query[i].l, posmap[query[i].x]);
                var rpos = LowerBound(0, query[i].r + 1, posmap[query[i].x]);
                segmap[query[i].x].AddRange(lpos, rpos, 1);
                lpos = LowerBound(0, query[i].l, alllist);
                rpos = LowerBound(0, query[i].r + 1, alllist);
                allseg.AddRange(lpos, rpos, 1);
            }
        }
        WriteLine(string.Join("\n", ans));
    }
    static int LowerBound(int left, int min, List<int> list)
    {
        if (list[left] >= min) return left;
        var ng = left;
        var ok = list.Count;
        while (ok - ng > 1)
        {
            var center = (ng + ok) / 2;
            if (list[center] < min) ng = center;
            else ok = center;
        }
        return ok;
    }
    class LazyAddSumSegmentTree
    {
        public long[] tree;
        public long[] lazy;
        /// <summary>範囲外を参照したときの値 欲しい値の種類によって変える</summary>
        long INF = 0;
        int size;
        public LazyAddSumSegmentTree(int[] list)
        {
            size = 1;
            while (size < list.Length) size <<= 1;
            tree = Enumerable.Repeat(INF, size * 2).ToArray();
            lazy = Enumerable.Repeat(INF, size * 2).ToArray();
            for (var i = 0; i < list.Length; ++i) tree[i + size] = list[i];
            for (var i = size - 1; i >= 1; --i) tree[i] = Calc(tree[i * 2], tree[i * 2 + 1]);
        }
        /// <summary>取得時の評価 欲しい値の種類によって変える</summary>
        long Calc(long a, long b)
        {
            return a + b;
        }
        /// <summary>遅延評価の値を適用する 区間に対する操作によって変える</summary>
        long Leval(long tval, long lval)
        {
            return tval + lval;
        }
        void Eval(int k)
        {
            if (lazy[k] == INF) return;
            if (k < size)
            {
                lazy[k * 2] = Calc(lazy[k * 2], lazy[k] / 2);
                lazy[k * 2 + 1] = Calc(lazy[k * 2 + 1], lazy[k] / 2);
            }
            tree[k] = Leval(tree[k], lazy[k]);
            lazy[k] = INF;
        }
        /// <summary>区間加算(end is not include)</summary>
        public void AddRange(int begin, int end, long value, int k = 1, int l = 0, int r = -1)
        {
            if (r < 0) r = size;
            Eval(k);
            if (begin <= l && r <= end)
            {
                lazy[k] += (r - l) * value;
                Eval(k);
            }
            else if (begin < r && l < end)
            {
                AddRange(begin, end, value, k * 2, l, (l + r) / 2);
                AddRange(begin, end, value, k * 2 + 1, (l + r) / 2, r);
                tree[k] = Calc(tree[k * 2], tree[k * 2 + 1]);
            }
        }
        /// <summary>値の取得(end is not include)</summary>
        public long Get(int begin, int end, int k = 1, int l = 0, int r = -1)
        {
            if (r < 0) r = size;
            Eval(k);
            if (begin <= l && r <= end) return tree[k];
            else if (begin < r && l < end)
                return Calc(Get(begin, end, k * 2, l, (l + r) / 2), Get(begin, end, k * 2 + 1, (l + r) / 2, r));
            else return INF;
        }
    }
}
0