QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100

#18770. 수열과 쿼리 12

Estadísticas

길이가 $N$인 수열 $A_1, A_2, \ldots, A_N$이 주어진다. 이때, 다음 쿼리를 수행하는 프로그램을 작성하시오.

  • 1 l r: $S$를 $l$번째 수부터 $r$번째 수까지 수로 이루어진 정렬된 집합이라고 했을 때, 다음을 출력한다. [\left(\sum_{1 \le i < j < k \le |S|}{S_iS_jS_k}\right) \mod{10^9+7}]
  • 2 x y: $A_x = y$
  • 3 x: $x$번째 수를 지운다
  • 4 z y: $z$번째 위치의 다음에 $y$를 추가한다. $z = 0$인 경우 가장 처음에 $y$를 추가하는 것이다.
  • 5 l r: $l$번째 수부터 $r$번째 수 중에서 서로 다른 수의 개수를 출력한다.

수열의 인덱스는 $1$부터 시작하며, 수열의 크기는 항상 $1$보다 크거나 같다.

입력

첫째 줄에 수열의 크기 $N$이 주어진다.

둘째 줄에는 $A_1, A_2, \ldots, A_N$이 주어진다.

셋째 줄에는 쿼리의 개수 $M$이 주어진다.

넷째 줄부터 $M$개의 줄에는 쿼리가 한 줄에 하나씩 주어진다.

  • $1 \le N, M \le 100{,}000$
  • $1 \le A_i, y \le 10^9+6$
  • $1 \le x \le |A|$
  • $1 \le l \le r \le |A|$
  • $0 \le z \le |A|$

출력

$1$번과 $5$번쿼리에 대해서 정답을 한 줄에 하나씩 순서대로 출력한다.

Sample

Input

5
1 2 3 2 1
8
1 1 3
5 1 5
2 2 4
1 2 4
3 3
4 0 5
1 1 2
1 1 5

Output

6
3
24
0
78

Sample

Input

10
5 4 3 5 4 1 5 4 3 1
15
2 8 580347
4 6 503576
1 2 5
5 8 11
1 2 6
4 7 565239
3 6
3 11
3 3
2 9 674360
1 1 6
2 2 589693
4 5 236488
1 8 9
5 2 7

Output

60
4
107
788510349
0
6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.