- Choose the aggregate stored for each interval or prefix.
- Build or initialize the structure from the input.
- Apply updates and combine the affected nodes to answer each query.
Code notes
- 91 lines of Python from the credited upstream file abc392_f.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Count the build once, then multiply the logarithmic update or query path by the number of operations.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3from typing import Any4 5 6class BIT:7 """Binary Indexed Tree (Fenwick Tree)8 9 See:10 https:atcoder.jp/contests/tessoku-book/submissions/3491243411 """12 13 def __init__(self, size: int) -> None:14 self.size = size15 self.size0 = 1 << (size.bit_length() - 1)16 self.tree = [0] * (size + 1)17 18 def add(self, index: int, value: Any) -> None:19 assert 0 <= index < self.size20 21 index += 122 23 while index <= self.size:24 self.tree[index] += value25 26 index += index & -index27 28 def get(self, index: int) -> Any:29 return self.sum(index) - self.sum(index - 1)30 31 def range_sum(self, left: int, right: int) -> Any:32 assert 0 <= left <= right <= self.size33 34 return self.sum(right - 1) - self.sum(left - 1)35 36 def sum(self, index: int) -> Any:37 index += 138 summed = 039 40 assert 0 <= index <= self.size41 42 while index > 0:43 summed += self.tree[index]44 index -= index & -index45 46 47 return summed48 49 def lower_bound(self, value: Any) -> int:50 pos = 051 plus = self.size052 53 while plus > 0:54 if pos + plus <= self.size and self.tree[pos + plus] < value:55 value -= self.tree[pos + plus]56 pos += plus57 58 plus = 259 60 return pos61 62 63def main():64 import sys65 66 input = sys.stdin.readline67 68 n = int(input())69 p = list(map(int, input().split()))70 71 bit = BIT(n + 10)72 73 for i in range(n):74 bit.add(i, 1)75 76 ans = [0] * n77 78 for i in range(n - 1, -1, -1):79 pi = p[i]80 j = bit.lower_bound(pi) 81 82 ans[j] = i + 1 83 84 bit.add(j, -1)85 86 print(*ans)87 88 89if __name__ == "__main__":90 main()91