P16028 [CSPro 23] Spiking Neural Network.

Background

Luogu’s testdata is for community communication only and is not official testdata. Official judging link: . In this problem, you need to implement a simulator for an SNN (spiking neural network). An SNN consists of the following parts: 1. Neurons: update internal states by certain formulas, receive spikes, and can fire spikes. 2. Spike sources: fire spikes at specific times. 3. Synapses: connect neuron-to-neuron or spike-source-to-neuron, and are responsible for transmitting spikes.

Description

A neuron updates its internal state following certain rules. In this problem, time is discretized: we set a time interval $\Delta t$, and only consider times $t = k\Delta t (k \in Z^+)$, and compute the variables at time $k$ from the values at time $k - 1$ using the following formulas: $$ \begin{aligned} v_k &= v_{k-1} + \Delta t(0.04v_{k-1}^2 + 5v_{k-1} + 140 - u_{k-1}) + I_k \\ u_k &= u_{k-1} + \Delta t a(bv_{k-1} - u_{k-1}) \end{aligned} $$ Here, $v$ and $u$ are internal variables of the neuron that change over time, while $a$ and $b$ are constants that do not change over time. $I_k$ is the sum of the strengths of all spike inputs received by this neuron at time $k$; if no spike is received, then $I_k = 0$. After the computation above, if $v_k \geq 30$, the neuron fires a spike, which is propagated to other neurons through synapses. Meanwhile, set $v_k$ to $c$ and set $u_k$ to $u_k + d$, where $c$ and $d$ are also constants. Figure 1 shows the curve of the neuron variable $v$ over time. :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/h2k0w5zt.png) ::: A synapse represents a connection between neuron-to-neuron or spike-source-to-neuron, and contains one input node and one output node (self-loops and multiple edges may exist). When the input node (a neuron or a spike source) fires a spike at time $k$, after a propagation delay of $D (D > 0)$ time steps, i.e. at time $k + D$, the output node (a neuron) will receive a spike with strength $w$. Each spike source fires a spike at each time with a certain probability. To simulate this process, each spike source has a parameter $0 < r \leq 32,767$, and the following pseudorandom function is used uniformly: C++ version: ```cpp static unsigned long next = 1; /* RAND_MAX assumed to be 32767 */ int myrand(void) { next = next * 1103515245 + 12345; return((unsigned)(next/65536) % 32768); } ``` Python version: ```python next = 1 def myrand(): global next next = (next * 1103515245 + 12345) % (2 ** 64) return (next // 65536) % 32768 ``` Java version: ```java long next = 1; int myrand() { next = next * 1103515245 + 12345; return (int)((Long.divideUnsigned(next, 65536)) % 32768); } ``` At each time step, in increasing order of their indices, each spike source calls the pseudorandom function once. If $r > \text{myrand}()$, it fires one spike at the current time, and the spike is propagated to neurons through synapses. During the simulation, the states of all neurons at time $0$ are known. Starting from time $1$, compute according to the rules above, until finishing the computation at time $T$. Then output the minimum and maximum values of neurons’ $v$ at time $T$, and the minimum and maximum numbers of spikes fired by neurons during the whole simulation. In the input, nodes are indexed in the following order: $[0, N - 1]$ are neuron indices, and $[N, N + P - 1]$ are spike source indices. Please use double-precision floating-point types in your code.

Input Format

Read input from standard input. The first line contains four positive integers $N\ S\ P\ T$ separated by spaces, meaning there are $N$ neurons, $S$ synapses, and $P$ spike sources, and you need to output the neurons’ $v$ values at time $T$. The second line contains a positive real number $\Delta t$, the time interval. The next several lines each contain one positive integer $R_N$ and six real numbers $v\ u\ a\ b\ c\ d$ separated by spaces. Each line corresponds to $R_N$ neurons that share the same initial state and constants: $v\ u$ are the values of the neuron variables at time $0$; $a\ b\ c\ d$ are the four constants in the neuron differential equation. It is guaranteed that the sum of all $R_N$ equals $N$. These lines describe the neurons in increasing index order, and each line corresponds to a consecutive segment of neuron indices. The next $P$ lines each contain one positive integer $r$. In order, each line gives the $r$ parameter of one spike source. The next $S$ lines each contain two integers $s (0 \leq s < N + P)$ and $t (0 \leq t < N)$, one real number $w (w \geq 0)$, and one positive integer $D$, separated by spaces. Here $s$ and $t$ are the indices of the input node and the output node; $w$ and $D$ are the spike strength and the propagation delay.

Output Format

Write output to standard output. There are two lines. The first line contains two real numbers rounded to 3 decimal places, which are the minimum and maximum of variable $v$ over all neurons at time $T$. The second line contains two integers, which are the minimum and maximum numbers of spikes fired by neurons during the whole simulation. As long as you implement according to the requirements, you will pass; you will not get a wrong answer due to precision issues.

Explanation/Hint

### Sample 1 Explanation This sample has 1 neuron, 1 synapse, and 1 spike source, with time interval $\Delta t = 0.1$. The only spike source connects to the only neuron through a synapse with spike strength $30.0$ and propagation delay $2$. This sample runs a simulation for 10 time steps. The random number generator produces 10 random numbers as follows: ``` 16838 5758 10113 17515 31051 5627 23010 7419 16212 4086 ``` Therefore, the only spike source fires spikes at times $1\text{-}4$ and $6\text{-}10$. From time $1$ to $10$, the neuron’s $v$ values are: ``` -70.000 -70.000 -40.000 -8.200 -65.000 -35.404 -32.895 0.181 -65.000 -35.608 ``` This neuron fires at time $5$ and time $9$, and the final result is $v = -35.608$. ### Subtasks | Subtask | $T$ | $N$ | $S$ | $P$ | $D$ | Score | |:------:|:---------:|:---------:|:---------:|:---------:|:--------:|:----:| | 1 | $\leq 10^2$ | $\leq 10^2$ | $\leq 10^2$ | $\leq 10^2$ | $\leq 10^2$ | 30 | | 2 | $\leq 10^3$ | $\leq 10^3$ | $\leq 10^3$ | $\leq 10^3$ | $\leq 10^3$ | 40 | | 3 | $\leq 10^5$ | ^ | ^ | ^ | $\leq 10$ | 30 | Translated by ChatGPT 5