Submission #49743811


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

public class E
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var N = Scanner.Scan<int>();
        var M = N * 3;
        var G = new List<int>[M].Select(x => new List<int>()).ToArray();
        for (var i = 0; i < N; i++)
        {
            var (a, b) = Scanner.Scan<int, int>();
            a--; b--;
            if (a > b) (a, b) = (b, a);
            if (b - a > N) (a, b) = (b, a + M);
            if (a + 1 != b) G[a].Add(b);
        }

        var stack = new Stack<int>();
        for (var a = 0; a < M; a++)
        {
            foreach (var b in G[a])
            {
                if (stack.Count > 0)
                {
                    var top = stack.Peek();
                    if (a < top && top < b)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            while (stack.Count > 0 && stack.Peek() < a)
            {
                stack.Pop();
            }

            foreach (var v in G[a])
            {
                stack.Push(v);
            }
        }

        Console.WriteLine("No");
    }

    public static int LowerBound<T>(List<T> source, T key, IComparer<T>? comparer = null)
        => LowerBound(System.Runtime.InteropServices.CollectionsMarshal.AsSpan(source), key, comparer);

    public static int LowerBound<T>(ReadOnlySpan<T> source, T key, IComparer<T>? comparer = null)
    {
        comparer ??= Comparer<T>.Default;
        var (lo, hi) = (-1, source.Length);
        while (hi - lo > 1)
        {
            var mi = lo + ((hi - lo) >> 1);
            if (comparer.Compare(source[mi], key) >= 0) hi = mi;
            else lo = mi;
        }

        return hi;
    }

    public static int UpperBound<T>(List<T> source, T key, IComparer<T>? comparer = null)
        => UpperBound(System.Runtime.InteropServices.CollectionsMarshal.AsSpan(source), key, comparer);

    public static int UpperBound<T>(ReadOnlySpan<T> source, T key, IComparer<T>? comparer = null)
    {
        comparer ??= Comparer<T>.Default;
        var (lo, hi) = (-1, source.Length);
        while (hi - lo > 1)
        {
            var mi = lo + ((hi - lo) >> 1);
            if (comparer.Compare(source[mi], key) > 0) hi = mi;
            else lo = mi;
        }

        return hi;
    }

    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

Submission Info

Submission Time
Task E - Chords
User AconCavy
Language C# 11.0 (.NET 7.0.7)
Score 500
Code Size 5108 Byte
Status AC
Exec Time 257 ms
Memory 96076 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 52 ms 26624 KiB
00_sample_01.txt AC 48 ms 26732 KiB
00_sample_02.txt AC 48 ms 26400 KiB
01_random_00.txt AC 84 ms 51920 KiB
01_random_01.txt AC 243 ms 95060 KiB
01_random_02.txt AC 257 ms 94856 KiB
01_random_03.txt AC 235 ms 94940 KiB
02_random2_00.txt AC 146 ms 64556 KiB
02_random2_01.txt AC 198 ms 95300 KiB
02_random2_02.txt AC 191 ms 94964 KiB
02_random2_03.txt AC 224 ms 95464 KiB
02_random2_04.txt AC 54 ms 32064 KiB
02_random2_05.txt AC 192 ms 95440 KiB
02_random2_06.txt AC 62 ms 31916 KiB
02_random2_07.txt AC 204 ms 95188 KiB
02_random2_08.txt AC 146 ms 65968 KiB
02_random2_09.txt AC 199 ms 95240 KiB
02_random2_10.txt AC 74 ms 44544 KiB
02_random2_11.txt AC 208 ms 95216 KiB
02_random2_12.txt AC 128 ms 65296 KiB
02_random2_13.txt AC 206 ms 95296 KiB
02_random2_14.txt AC 68 ms 37692 KiB
02_random2_15.txt AC 221 ms 95188 KiB
02_random2_16.txt AC 65 ms 39452 KiB
02_random2_17.txt AC 211 ms 95296 KiB
02_random2_18.txt AC 89 ms 54540 KiB
02_random2_19.txt AC 237 ms 95192 KiB
03_handmade_00.txt AC 48 ms 26896 KiB
03_handmade_01.txt AC 48 ms 26516 KiB
03_handmade_02.txt AC 185 ms 91268 KiB
03_handmade_03.txt AC 231 ms 96076 KiB