2963. 宝石机关

摘要
Title: 2963. 宝石机关
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

2963. 宝石机关

  • 题意

  • 思路

    思路就是开三个哈希表,先让第一个哈希表把p的所有数打上表示,当p[i]遍历到时,判断a - p[i]和 b - p[i]是否存在,如果存在就抹去第一个的标记,去标记A或B数组

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    '''
    Author: NEFU AB-IN
    Date: 2023-06-09 23:46:37
    FilePath: \LanQiao\2963\2963.py
    LastEditTime: 2023-06-10 00:31:47
    '''
    # import
    from sys import setrecursionlimit, stdin, stdout, exit
    from collections import Counter, deque
    from heapq import heapify, heappop, heappush, nlargest, nsmallest
    from bisect import bisect_left, bisect_right
    from datetime import datetime, timedelta
    from string import ascii_lowercase, ascii_uppercase
    from math import log, gcd, sqrt, fabs, ceil, floor


    class sa:
    def __init__(self, x, y):
    self.x = x
    self.y = y

    def __lt__(self, a):
    return self.x < a.x


    # Final
    N = int(1e5 + 10)
    M = 20
    INF = int(2e9)

    # Define
    setrecursionlimit(INF)
    input = lambda: stdin.readline().rstrip("\r\n") # Remove when Mutiple data
    read = lambda: map(int, input().split())
    LTN = lambda x: ord(x.upper()) - 65 # A -> 0
    NTL = lambda x: ascii_uppercase[x] # 0 -> A

    # —————————————————————Division line ——————————————————————

    p = [0] * N

    n, a, b = read()
    p[1:] = read()

    A, B, d = Counter(), Counter(), Counter()

    for i in range(1, n + 1):
    d[p[i]] = 1

    for i in range(1, n + 1):
    if d[p[i]] == 0:
    continue
    if d[a - p[i]] == 1 or A[a - p[i]] == 1:
    A[a - p[i]] = 1
    A[p[i]] = 1
    d[a - p[i]] = 0
    d[p[i]] = 0
    elif d[b - p[i]] == 1 or B[b - p[i]] == 1:
    B[b - p[i]] = 1
    B[p[i]] = 1
    d[b - p[i]] = 0
    d[p[i]] = 0
    else:
    print("NO")
    exit(0)

    print("YES")
    for i in range(1, n + 1):
    if A[p[i]]:
    print(0, end = " ")
    else:
    print(1, end = " ")

使用搜索:谷歌必应百度