• codeforces:C. Almost All Multiples【构造 + 贪心】


    题目截图

    在这里插入图片描述

    题目分析

    • 现在p1 = x, pn = 1
    • 如果我们一开始按1234…这样放字典序是最小的
    • 所以根据这个思路,我们还是按这个构造:那么我们的n被挤出来了,只能放到px上
    • 所以如果一开始x不能整除n的话,就直接-1了
    • 如果能的话,我们希望得到最小的字典序
    • 思路也就是贪心,从左到右遍历i,一碰到i和x能交换的就交换
    • 因为这样交换替换的px一定是最小的
    • 能交换的条件是:a[x] % (i + 1) = 0 and a[i] % (x + 1) = 0
    • 交换后更新一下x = i即可,继续向后遍历i
    • 注意到i >= x + 1,所以x是单调递增的
    • 就是说,我们把n最放最靠后了,也是符合目标的
    • 同时我们交换n的时候,那个交换到x位置的是一定也是最小的

    ac code

    # -*- coding: utf-8 -*-
    # @Time    : 2022/12/2 15:51
    # @Author  : bridgekiller
    # @FileName: 1758C.py
    # @Software: PyCharm
    # @Blog    :bridge-killer.blog.csdn.net
    
    import os
    import sys
    import math
    import random
    import threading
    from copy import deepcopy
    from io import BytesIO, IOBase
    from types import GeneratorType
    from functools import lru_cache, reduce
    from bisect import bisect_left, bisect_right
    from collections import Counter, defaultdict, deque
    from itertools import accumulate, combinations, permutations
    from heapq import nsmallest, nlargest, heapify, heappop, heappush
    from typing import Generic, Iterable, Iterator, TypeVar, Union, List
    
    
    def debug(func):
        def wrapper(*args, **kwargs):
            print('----------------')
            res = func(*args, **kwargs)
            print('----------------')
            return res
    
        return wrapper
    
    
    def bootstrap(f, stack=[]):
        def wrappedfunc(*args, **kwargs):
            if stack:
                return f(*args, **kwargs)
            else:
                to = f(*args, **kwargs)
                while True:
                    if type(to) is GeneratorType:
                        stack.append(to)
                        to = next(to)
                    else:
                        stack.pop()
                        if not stack:
                            break
                        to = stack[-1].send(to)
                return to
    
        return wrappedfunc
    
    
    class SegTree:
        '''
        支持增量更新,覆盖更新,序列更新,任意RMQ操作
        基于二叉树实现
        初始化:O(1)
        增量更新或覆盖更新的单次操作复杂度:O(log k)
        序列更新的单次复杂度:O(n)
        '''
    
        def __init__(self, f1, f2, l, r, v=0):
            '''
            初始化线段树[left,right)
            f1,f2示例:
            线段和:
            f1=lambda a,b:a+b
            f2=lambda a,n:a*n
            线段最大值:
            f1=lambda a,b:max(a,b)
            f2=lambda a,n:a
            线段最小值:
            f1=lambda a,b:min(a,b)
            f2=lambda a,n:a
            '''
            self.ans = f2(v, r - l)
            self.f1 = f1
            self.f2 = f2
            self.l = l  # left
            self.r = r  # right
            self.v = v  # init value
            self.lazy_tag = 0  # Lazy tag
            self.left = None  # SubTree(left,bottom)
            self.right = None  # SubTree(right,bottom)
    
        @property
        def mid_h(self):
            return (self.l + self.r) // 2
    
        def create_subtrees(self):
            midh = self.mid_h
            if not self.left and midh > self.l:
                self.left = SegTree(self.f1, self.f2, self.l, midh)
            if not self.right:
                self.right = SegTree(self.f1, self.f2, midh, self.r)
    
        def init_seg(self, M):
            '''
            将线段树的值初始化为矩阵Matrx
            输入保证Matrx与线段大小一致
            '''
            m0 = M[0]
            self.lazy_tag = 0
            for a in M:
                if a != m0:
                    break
            else:
                self.v = m0
                self.ans = self.f2(m0, len(M))
                return self.ans
            self.v = '#'
            midh = self.mid_h
            self.create_subtrees()
            self.ans = self.f1(self.left.init_seg(M[:midh - self.l]), self.right.init_seg(M[midh - self.l:]))
            return self.ans
    
        def cover_seg(self, l, r, v):
            '''
            将线段[left,right)覆盖为val
            '''
            if self.v == v or l >= self.r or r <= self.l:
                return self.ans
            if l <= self.l and r >= self.r:
                self.v = v
                self.lazy_tag = 0
                self.ans = self.f2(v, self.r - self.l)
                return self.ans
            self.create_subtrees()
            if self.v != '#':
                if self.left:
                    self.left.v = self.v
                    self.left.ans = self.f2(self.v, self.left.r - self.left.l)
                if self.right:
                    self.right.v = self.v
                    self.right.ans = self.f2(self.v, self.right.r - self.right.l)
                self.v = '#'
            # push up
            self.ans = self.f1(self.left.cover_seg(l, r, v), self.right.cover_seg(l, r, v))
            return self.ans
    
        def inc_seg(self, l, r, v):
            '''
            将线段[left,right)增加val
            '''
            if v == 0 or l >= self.r or r <= self.l:
                return self.ans
            # self.ans = '?'
            if l <= self.l and r >= self.r:
                if self.v == '#':
                    self.lazy_tag += v
                else:
                    self.v += v
                self.ans += self.f2(v, self.r - self.l)
                return self.ans
            self.create_subtrees()
            if self.v != '#':
                self.left.v = self.v
                self.left.ans = self.f2(self.v, self.left.r - self.left.l)
                self.right.v = self.v
                self.right.ans = self.f2(self.v, self.right.r - self.right.l)
                self.v = '#'
            self.pushdown()
            self.ans = self.f1(self.left.inc_seg(l, r, v), self.right.inc_seg(l, r, v))
            return self.ans
    
        def inc_idx(self, idx, v):
            '''
            increase idx by val
            '''
            if v == 0 or idx >= self.r or idx < self.l:
                return self.ans
            if idx == self.l == self.r - 1:
                self.v += v
                self.ans += self.f2(v, 1)
                return self.ans
            self.create_subtrees()
            if self.v != '#':
                self.left.v = self.v
                self.left.ans = self.f2(self.v, self.left.r - self.left.l)
                self.right.v = self.v
                self.right.ans = self.f2(self.v, self.right.r - self.right.l)
                self.v = '#'
            self.pushdown()
            self.ans = self.f1(self.left.inc_idx(idx, v), self.right.inc_idx(idx, v))
            return self.ans
    
        def pushdown(self):
            if self.lazy_tag != 0:
                if self.left:
                    if self.left.v != '#':
                        self.left.v += self.lazy_tag
                        self.left.lazy_tag = 0
                    else:
                        self.left.lazy_tag += self.lazy_tag
                    self.left.ans += self.f2(self.lazy_tag, self.left.r - self.left.l)
                if self.right:
                    if self.right.v != '#':
                        self.right.v += self.lazy_tag
                        self.right.lazy_tag = 0
                    else:
                        self.right.lazy_tag += self.lazy_tag
                    self.right.ans += self.f2(self.lazy_tag, self.right.r - self.right.l)
                self.lazy_tag = 0
    
        def query(self, l, r):
            '''
            查询线段[right,bottom)的RMQ
            '''
            if l >= r: return 0
            if l <= self.l and r >= self.r:
                return self.ans
            if self.v != '#':
                return self.f2(self.v, min(self.r, r) - max(self.l, l))
            midh = self.mid_h
            anss = []
            if l < midh:
                anss.append(self.left.query(l, r))
            if r > midh:
                anss.append(self.right.query(l, r))
            return reduce(self.f1, anss)
    
    
    class SortedList:
        def __init__(self, iterable=[], _load=200):
            """Initialize sorted list instance."""
            values = sorted(iterable)
            self._len = _len = len(values)
            self._load = _load
            self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
            self._list_lens = [len(_list) for _list in _lists]
            self._mins = [_list[0] for _list in _lists]
            self._fen_tree = []
            self._rebuild = True
    
        def _fen_build(self):
            """Build a fenwick tree instance."""
            self._fen_tree[:] = self._list_lens
            _fen_tree = self._fen_tree
            for i in range(len(_fen_tree)):
                if i | i + 1 < len(_fen_tree):
                    _fen_tree[i | i + 1] += _fen_tree[i]
            self._rebuild = False
    
        def _fen_update(self, index, value):
            """Update `fen_tree[index] += value`."""
            if not self._rebuild:
                _fen_tree = self._fen_tree
                while index < len(_fen_tree):
                    _fen_tree[index] += value
                    index |= index + 1
    
        def _fen_query(self, end):
            """Return `sum(_fen_tree[:end])`."""
            if self._rebuild:
                self._fen_build()
    
            _fen_tree = self._fen_tree
            x = 0
            while end:
                x += _fen_tree[end - 1]
                end &= end - 1
            return x
    
        def _fen_findkth(self, k):
            """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
            _list_lens = self._list_lens
            if k < _list_lens[0]:
                return 0, k
            if k >= self._len - _list_lens[-1]:
                return len(_list_lens) - 1, k + _list_lens[-1] - self._len
            if self._rebuild:
                self._fen_build()
    
            _fen_tree = self._fen_tree
            idx = -1
            for d in reversed(range(len(_fen_tree).bit_length())):
                right_idx = idx + (1 << d)
                if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                    idx = right_idx
                    k -= _fen_tree[idx]
            return idx + 1, k
    
        def _delete(self, pos, idx):
            """Delete value at the given `(pos, idx)`."""
            _lists = self._lists
            _mins = self._mins
            _list_lens = self._list_lens
    
            self._len -= 1
            self._fen_update(pos, -1)
            del _lists[pos][idx]
            _list_lens[pos] -= 1
    
            if _list_lens[pos]:
                _mins[pos] = _lists[pos][0]
            else:
                del _lists[pos]
                del _list_lens[pos]
                del _mins[pos]
                self._rebuild = True
    
        def _loc_left(self, value):
            """Return an index pair that corresponds to the first position of `value` in the sorted list."""
            if not self._len:
                return 0, 0
    
            _lists = self._lists
            _mins = self._mins
    
            lo, pos = -1, len(_lists) - 1
            while lo + 1 < pos:
                mi = (lo + pos) >> 1
                if value <= _mins[mi]:
                    pos = mi
                else:
                    lo = mi
    
            if pos and value <= _lists[pos - 1][-1]:
                pos -= 1
    
            _list = _lists[pos]
            lo, idx = -1, len(_list)
            while lo + 1 < idx:
                mi = (lo + idx) >> 1
                if value <= _list[mi]:
                    idx = mi
                else:
                    lo = mi
    
            return pos, idx
    
        def _loc_right(self, value):
            """Return an index pair that corresponds to the last position of `value` in the sorted list."""
            if not self._len:
                return 0, 0
    
            _lists = self._lists
            _mins = self._mins
    
            pos, hi = 0, len(_lists)
            while pos + 1 < hi:
                mi = (pos + hi) >> 1
                if value < _mins[mi]:
                    hi = mi
                else:
                    pos = mi
    
            _list = _lists[pos]
            lo, idx = -1, len(_list)
            while lo + 1 < idx:
                mi = (lo + idx) >> 1
                if value < _list[mi]:
                    idx = mi
                else:
                    lo = mi
    
            return pos, idx
    
        def add(self, value):
            """Add `value` to sorted list."""
            _load = self._load
            _lists = self._lists
            _mins = self._mins
            _list_lens = self._list_lens
    
            self._len += 1
            if _lists:
                pos, idx = self._loc_right(value)
                self._fen_update(pos, 1)
                _list = _lists[pos]
                _list.insert(idx, value)
                _list_lens[pos] += 1
                _mins[pos] = _list[0]
                if _load + _load < len(_list):
                    _lists.insert(pos + 1, _list[_load:])
                    _list_lens.insert(pos + 1, len(_list) - _load)
                    _mins.insert(pos + 1, _list[_load])
                    _list_lens[pos] = _load
                    del _list[_load:]
                    self._rebuild = True
            else:
                _lists.append([value])
                _mins.append(value)
                _list_lens.append(1)
                self._rebuild = True
    
        def discard(self, value):
            """Remove `value` from sorted list if it is a member."""
            _lists = self._lists
            if _lists:
                pos, idx = self._loc_right(value)
                if idx and _lists[pos][idx - 1] == value:
                    self._delete(pos, idx - 1)
    
        def remove(self, value):
            """Remove `value` from sorted list; `value` must be a member."""
            _len = self._len
            self.discard(value)
            if _len == self._len:
                raise ValueError('{0!r} not in list'.format(value))
    
        def pop(self, index=-1):
            """Remove and return value at `index` in sorted list."""
            pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
            value = self._lists[pos][idx]
            self._delete(pos, idx)
            return value
    
        def bisect_left(self, value):
            """Return the first index to insert `value` in the sorted list."""
            pos, idx = self._loc_left(value)
            return self._fen_query(pos) + idx
    
        def bisect_right(self, value):
            """Return the last index to insert `value` in the sorted list."""
            pos, idx = self._loc_right(value)
            return self._fen_query(pos) + idx
    
        def count(self, value):
            """Return number of occurrences of `value` in the sorted list."""
            return self.bisect_right(value) - self.bisect_left(value)
    
        def __len__(self):
            """Return the size of the sorted list."""
            return self._len
    
        def __getitem__(self, index):
            """Lookup value at `index` in sorted list."""
            pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
            return self._lists[pos][idx]
    
        def __delitem__(self, index):
            """Remove value at `index` from sorted list."""
            pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
            self._delete(pos, idx)
    
        def __contains__(self, value):
            """Return true if `value` is an element of the sorted list."""
            _lists = self._lists
            if _lists:
                pos, idx = self._loc_left(value)
                return idx < len(_lists[pos]) and _lists[pos][idx] == value
            return False
    
        def __iter__(self):
            """Return an iterator over the sorted list."""
            return (value for _list in self._lists for value in _list)
    
        def __reversed__(self):
            """Return a reverse iterator over the sorted list."""
            return (value for _list in reversed(self._lists) for value in reversed(_list))
    
        def __repr__(self):
            """Return string representation of sorted list."""
            return 'SortedList({0})'.format(list(self))
    
    
    T = TypeVar('T')
    
    
    class SortedSet(Generic[T]):
        BUCKET_RATIO = 50
        REBUILD_RATIO = 170
    
        def _build(self, a=None) -> None:
            "Evenly divide `a` into buckets."
            if a is None: a = list(self)
            size = self.size = len(a)
            bucket_size = int(math.ceil(math.sqrt(size / self.BUCKET_RATIO)))
            self.a = [a[size * i // bucket_size: size * (i + 1) // bucket_size] for i in range(bucket_size)]
    
        def __init__(self, a: Iterable[T] = []) -> None:
            "Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)"
            a = list(a)
            if not all(a[i] < a[i + 1] for i in range(len(a) - 1)):
                a = sorted(set(a))
            self._build(a)
    
        def __iter__(self) -> Iterator[T]:
            for i in self.a:
                for j in i: yield j
    
        def __reversed__(self) -> Iterator[T]:
            for i in reversed(self.a):
                for j in reversed(i): yield j
    
        def __len__(self) -> int:
            return self.size
    
        def __repr__(self) -> str:
            return "SortedSet" + str(self.a)
    
        def __str__(self) -> str:
            s = str(list(self))
            return "{" + s[1: len(s) - 1] + "}"
    
        def _find_bucket(self, x: T) -> List[T]:
            "Find the bucket which should contain x. self must not be empty."
            for a in self.a:
                if x <= a[-1]: return a
            return a
    
        def __contains__(self, x: T) -> bool:
            if self.size == 0: return False
            a = self._find_bucket(x)
            i = bisect_left(a, x)
            return i != len(a) and a[i] == x
    
        def add(self, x: T) -> bool:
            "Add an element and return True if added. / O(√N)"
            if self.size == 0:
                self.a = [[x]]
                self.size = 1
                return True
            a = self._find_bucket(x)
            i = bisect_left(a, x)
            if i != len(a) and a[i] == x: return False
            a.insert(i, x)
            self.size += 1
            if len(a) > len(self.a) * self.REBUILD_RATIO:
                self._build()
            return True
    
        def discard(self, x: T) -> bool:
            "Remove an element and return True if removed. / O(√N)"
            if self.size == 0: return False
            a = self._find_bucket(x)
            i = bisect_left(a, x)
            if i == len(a) or a[i] != x: return False
            a.pop(i)
            self.size -= 1
            if len(a) == 0: self._build()
            return True
    
        def lt(self, x: T) -> Union[T, None]:
            "Find the largest element < x, or None if it doesn't exist."
            for a in reversed(self.a):
                if a[0] < x:
                    return a[bisect_left(a, x) - 1]
    
        def le(self, x: T) -> Union[T, None]:
            "Find the largest element <= x, or None if it doesn't exist."
            for a in reversed(self.a):
                if a[0] <= x:
                    return a[bisect_right(a, x) - 1]
    
        def gt(self, x: T) -> Union[T, None]:
            "Find the smallest element > x, or None if it doesn't exist."
            for a in self.a:
                if a[-1] > x:
                    return a[bisect_right(a, x)]
    
        def ge(self, x: T) -> Union[T, None]:
            "Find the smallest element >= x, or None if it doesn't exist."
            for a in self.a:
                if a[-1] >= x:
                    return a[bisect_left(a, x)]
    
        def __getitem__(self, x: int) -> T:
            "Return the x-th element, or IndexError if it doesn't exist."
            if x < 0: x += self.size
            if x < 0: raise IndexError
            for a in self.a:
                if x < len(a): return a[x]
                x -= len(a)
            raise IndexError
    
        def index(self, x: T) -> int:
            "Count the number of elements < x."
            ans = 0
            for a in self.a:
                if a[-1] >= x:
                    return ans + bisect_left(a, x)
                ans += len(a)
            return ans
    
        def index_right(self, x: T) -> int:
            "Count the number of elements <= x."
            ans = 0
            for a in self.a:
                if a[-1] > x:
                    return ans + bisect_right(a, x)
                ans += len(a)
            return ans
    
    
    BUFSIZE = 4096
    
    
    class FastIO(IOBase):
        newlines = 0
    
        def __init__(self, file):
            self._fd = file.fileno()
            self.buffer = BytesIO()
            self.writable = "x" in file.mode or "r" not in file.mode
            self.write = self.buffer.write if self.writable else None
    
        def read(self):
            while True:
                b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                if not b:
                    break
                ptr = self.buffer.tell()
                self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines = 0
            return self.buffer.read()
    
        def readline(self):
            while self.newlines == 0:
                b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
                self.newlines = b.count(b"\n") + (not b)
                ptr = self.buffer.tell()
                self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
            self.newlines -= 1
            return self.buffer.readline()
    
        def flush(self):
            if self.writable:
                os.write(self._fd, self.buffer.getvalue())
                self.buffer.truncate(0), self.buffer.seek(0)
    
    
    class IOWrapper(IOBase):
        def __init__(self, file):
            self.buffer = FastIO(file)
            self.flush = self.buffer.flush
            self.writable = self.buffer.writable
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")
    
    
    sys.stdin = IOWrapper(sys.stdin)
    sys.stdout = IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
    
    
    def I():
        return input()
    
    
    def II():
        return int(input())
    
    
    def MI():
        return map(int, input().split())
    
    
    def LI():
        return list(input().split())
    
    
    def LII():
        return list(map(int, input().split()))
    
    
    def GMI():
        return map(lambda x: int(x) - 1, input().split())
    
    
    def LGMI():
        return list(map(lambda x: int(x) - 1, input().split()))
    
    
    def solve():
        n, x = LII()
        if n % x: # n想放到x上
            return print(-1)
        a = list(range(1, n + 1))
        if n == x:
            a[0], a[-1] = a[-1], a[0]
            return print(*a)
        # 1和x放了,n就放到x那里
        a[0], a[-1], a[x - 1] = x, 1, n
        x -= 1
        # 获得最小字典序
        for i in range(1, n-1):
            # i >= x
            # a[i] and a[x]是可以交换的
            # n能往后挪就往后挪
            if a[x] % (i + 1) == 0 and a[i] % (x + 1) == 0:
                a[i], a[x] = a[x], a[i]
                x = i
        print(*a)
    
    
    if __name__ == '__main__':
        for _ in range(II()):
            solve()
    
    
    • 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
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693

    总结

    • 最小字典序联想到12345…
    • 固定了p1和pn的值,联想到px = n
    • 为了获得最小字典序,需要让n尽可能往后,需要与后面元素交换
    • 同一个位置或许有多个能和x交换的i(i > x)
    • 我们选最近的,因为这样第x个位置上的数就会最小
    • 一方面使得n放的相对后,另一方面使得n之前的位置放的数是最小的
  • 相关阅读:
    论文解读(GCC)《Efficient Graph Convolution for Joint Node RepresentationLearning and Clustering》
    『网易实习』周记(三)
    下载安装nvm,使用nvm管理node.js版本
    [Qt][C++]static与extern关键字
    基于华为云服务器Docker nginx安装和配置挂载
    SpringBoot复习:(60)文件上传的自动配置类MultipartAutoConfiguration
    基于SqlSugar的开发框架循序渐进介绍(2)-- 基于中间表的查询处理
    机器学习 —— 简单模型的构建
    微信开发者工具如何使用?使用注意事项
    【Jmeter 简单使用】
  • 原文地址:https://blog.csdn.net/weixin_40986490/article/details/128150614