목차

blobhyperthink

ps
링크acmicpc.net/…
출처BOJ
문제 번호24505
문제명blobhyperthink
레벨플래티넘 4
분류

구간쿼리

시간복잡도O(nlogn)
인풋사이즈n<=10^5
사용한 언어Python 3.11
제출기록52812KB / 3088ms
최고기록2952ms
해결날짜2023/08/04

풀이

코드

"""Solution code for "BOJ 24505. blobhyperthink".

- Problem link: https://www.acmicpc.net/problem/24505
- Solution link: http://www.teferi.net/ps/problems/boj/24505

Tags: [segment tree]
"""

import sys
from teflib import fenwicktree

MOD = 10**9 + 7


def main():
    N = int(sys.stdin.readline())
    A = [int(x) for x in sys.stdin.readline().split()]

    cur_counts = [1] * N
    for _ in range(10):
        cur_counts, prev_counts = [0] * N, cur_counts
        ost = fenwicktree.OrderStatisticTree(N + 1)
        for i, a_i in enumerate(A):
            cur_counts[i] = ost.count_less_than(a_i) % MOD
            ost.add(a_i, prev_counts[i])

    print(sum(cur_counts) % MOD)


if __name__ == '__main__':
    main()