시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 1024 MB | 1 | 1 | 1 | 100.000% |
$\color{blue}{\text{LaLa}}$ is about to cast a $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$al beast summoning $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$.
The first thing $\color{blue}{\text{LaLa}}$ do is creating a summoning field, which has 3 constants associated with it: nullity $M$, elasticity $E$, and viscosity $V$. Such summoning field is denoted by $\mathcal{F}(M, E, V)$
A $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$al beast summoning $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$ is performed over a summoning cell within the summoning field, which is square-shaped and is associated with 3 variables: side length $L$, agility $A$, and intelligence $I$. Such summoning cell is denoted by $\mathcal{C}(L, A, I)$.
$\mathcal{C}(L, A, I)$ is in a null state if $L=0$. Otherwise, it is in a positive state.
The density of $\mathcal{C}(L, A, I)$ in positive state is defined as $(A \times I) / L^2$.
The problem of determining whether a $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$al beast summoning $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$ will succeed requires very heavy computation involving solving a system of $9999999999$-th order partial differential equations over $9999999999999999$ variables. Fortunately, $\color{blue}{\text{LaLa}}$ already did all the math for you!
The $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$al beast summoning $\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}$ over $\mathcal{C}(L, A, I)$ within $\mathcal{F}(M, E, V)$ succeeds if and only if the function $\textrm{valid}(M, E, V, L, A, I)$ defined by the pseudocode in the note section returns true. We'll call such summoning cell valid.
Sometimes, $\color{blue}{\text{LaLa}}$ isn't satisfied with the set of summoning cells she has, and wants to generate new ones by combining them. The problem of determining the result of combination of two valid summoning cells $C_0 = \mathcal{C}(L_0, A_0, I_0)$ and $C_1 = \mathcal{C}(L_1, A_1, I_1)$ within $F = \mathcal{F}(M, E, V)$ requires another heavy computation, but thankfully, $\color{blue}{\text{LaLa}}$ already did all the math for you again!
The result of combining two such cells $C_0$ and $C_1$ within $F$, denoted by $\textrm{Combine}_F(C_0, C_1)$, is given by the function $\textrm{combine}(M, E, V, L_0, A_0, I_0, L_1, A_1, I_1)$ defined by the pseudocode in the note section, which returns a triple $L_2, A_2, I_2$ satisfying $\mathcal{C}(L_2, A_2, I_2) = \textrm{Combine}_F(C_0, C_1)$. Here, it can be proved that $\textrm{Combine}_F(C_0, C_1)$ is also valid. Note that swapping the order of $C_0$ and $C_1$ affects the result.
The result of combining $K \ge 3$ cells $C_0, \cdots, C_{K-1}$ within $F$ is given recursively by $$\textrm{Combine}_F(C_0, \cdots, C_{K-1}) = \textrm{Combine}_F(\textrm{Combine}_F(C_0, \cdots, C_{K-2}), C_{K-1})$$
For the sake of completeness, we define $\textrm{Combine}_F(C)=C$.
$\color{blue}{\text{LaLa}}$ is aware of a very special property about the combining operation that allows her to efficiently solve the range density query problem below. Can you figure it out?
You're given a summoning field $F=\mathcal{F}(M, E, V)$ and an array of $N$ valid summoning cells $$C_0 = \mathcal{C}(L_0, A_0, I_0), \cdots, C_{N-1} = \mathcal{C}(L_{N-1}, A_{N-1}, I_{N-1})$$ within $F$. Write a program that processes the following two types of $Q$ queries:
1 i L A I
2 l r
The input is given in the following format:
$M$ $E$ $V$
$N$
$L_0$ $A_0$ $I_0$
$\vdots$
$L_{N-1}$ $A_{N-1}$ $I_{N-1}$
$Q$
$q_0$
$\vdots$
$q_{Q - 1}$
Here, $q_i$ denotes the $i$-th query, and is given in the format described in the statement.
The input satisfies the following constraints:
1 i L A I
, $0 \le i < N$, $0 \le L, A, I < M$, and $\mathcal{C}(L, A, I)$ is valid within $\mathcal{F}(M, E, V)$.2 l r
, $0 \le l < r \le N$For each query of the second type, print its answer in a single line.
998244353 1 2 3 2 998244352 3 4 998244351 6 4 929561374 68682991 7 2 0 2 2 0 3 2 1 3 1 1 6 9 998244350 2 0 2 2 0 3 2 1 3
-1 748683259 156877648 748683265 499122176 342244251
The following pseudocode defines the validity of summoning cells and the $\textrm{Combine}$ operation.
Both functions do not modify their arguments
The author has attached a C++ implementation which will get "Time Limit Exceeded" verdict upon submission, but it will always print the correct answer within finite time. You may reuse some part of the implementation on your submission. You can find it on the "Problemset" tab on the domjudge site.
Camp > Osijek Competitive Programming Camp > Winter 2023 > Day 9: Magical Story of LaLa J번