P5510 Crystal

Background

2019/12/27: Modified the Constraints of the last test point. Steve led his army to the stronghold of the dark forces. However, he found that the dark forces were using crystals to protect themselves. To break through the defense, Steve began attacking the crystals with weapons.

Description

The dark forces’ crystals have been lined up in a row, and there are many of them. The crystals can be divided into $n$ groups. The $i$-th group contains $a_i$ crystals, and their defense value is $na_i$. Steve’s weapons have also been lined up in a row, and there are many of them. The weapons can also be divided into $n$ groups. The $i$-th group contains $b_i$ weapons, and their attack value is $nb_i$. In each round of attack, the dark forces will choose one crystal, and Steve will choose one weapon. If the weapon’s attack value is greater than the crystal’s defense value, then this attack is effective. However, there are too many crystals and weapons, so it is hard for Steve to know exactly which crystal and which weapon were chosen. Now Steve wants to know: 1. For all possible situations, how many ways of choosing result in an effective attack. 2. If it is already known that the chosen crystal’s defense value is between the defense values of the crystals in group $x$ and group $y$, and the chosen weapon’s attack value is between the attack values of the weapons in group $z$ and group $u$, then how many ways of choosing result in an effective attack. That is, the chosen crystal’s defense value is not less than the smaller of the defense values of group $x$ and group $y$, and not greater than the larger of them; similarly for the weapon. Two choices are different if and only if the chosen crystal or the chosen weapon is different (they may be in the same group). Since the battle is urgent, you need to answer the questions quickly so that Steve can decide the next round of attacks. Therefore, some test points require online answering. To avoid the answer being too large, take the answer modulo $998244353$.

Input Format

Because the input/output size is large, use the following template to generate the data. For the exact format, see the template and samples. During judging, all test points will only input 5 numbers and output 1 number, so you do not need to optimize input/output. For easier debugging, this template can manually specify the data and output the answer to each query; in that case you only need to input $k=0$. For all test points, it is guaranteed that the time consumed by calling the interaction library does not exceed 300 ms. ``` #include using namespace std; #define u32 unsigned int #define u64 unsigned long long int cl; const int N=2500007; const long long M=998244353LL; int n,q,k; int a[N],na[N],b[N],nb[N]; int x,y,z,u; namespace lib{ u64 read(){ u64 n=0; char c=getchar(); while(c'9')c=getchar(); while(c>='0'&&c>8)%(r-l+1)+l); } int ra,t; void init(){ n=read();k=read(); if(k8)%(M-1)+1); //na[i]=rand(1,M-1); } s=bacs; for(int i=1;i>8)%ra+1); //a[i]=rand(1,ra); s=s*19260817+1; na[i]=((s>>8)%(M-1)+1); //na[i]=rand(1,M-1); } bacs=s; for(int i=1;i>8)%ra+1); //a[i]=rand(1,ra); s=s*19260817+1; //nb[i]=((s>>8)%(M-1)+1); } s=bacs; for(int i=1;i>8)%ra+1); //a[i]=rand(1,ra); s=s*19260817+1; nb[i]=((s>>8)%(M-1)+1); } } q=read(); } u64 lastans; u64 res; void reply(u64 num){ if(k8)%n+1); s=s*19260817+1; y=((s>>8)%n+1); s=s*19260817+1; z=((s>>8)%n+1); s=s*19260817+1; u=((s>>8)%n+1); //x=rand(1,n);y=rand(1,n);z=rand(1,n);u=rand(1,n); } if(k&1){ int t=lastans%n+1; if((x+=t)>n)x-=n; if((y+=t)>n)y-=n; if((z+=t)>n)z-=n; if((u+=t)>n)u-=n; /*x=(x+lastans)%n+1; y=(y+lastans)%n+1; z=(z+lastans)%n+1; u=(u+lastans)%n+1;*/ } } void stop(){ if(k>=2){write(res);putchar('\n');} } } int main(){ lib::init(); //现在你可以使用生成的a,na,b,nb //回答第一问 lib::reply(233); for(int i=1;i

Output Format

If $k=0$, the answer to each question will be output separately. Otherwise, only one integer will be output to check whether the result is correct.

Explanation/Hint

Explanation for Sample 1: When choosing the weapons in the second group, you can always make an effective attack. When choosing the weapons in the first group, only choosing the crystals in the first group can make an effective attack. Therefore, it is not hard to find the answer to each question. It is recommended to further understand the statement based on the samples. Sample 5 is the same as Sample 6. Constraints: For all data, $1 \le x,y,z,u \le n$, $1 \le a_i,b_i \le 10^9$, and $1 \le na_i,nb_i \le 998244352$. Unless otherwise specified, $k=3$, i.e., the data is generated by the template and online answering is required. If $k=2$, the data is still generated by the generator, but online answering is not required. That is, you can get the real value of the next query without answering the current query, and then answer them in order afterward. Test Point | Score | $n$ | $q$ | Special Property :-: | :-: | :-: | :-: | :-: 1 | 4 | 100 | 100 | $k=2$ 2 | 14 | 3000 | 3000 | $k=2$ 3 | 11 | 100000 | 100000 | $a_i,b_i \le 100$ 4 | 10 | 15 | 4000000 | 5 | 12 | 100 | 4000000 | 6 | 14 | 5000 | 4000000 | 7 | 16 | 100000 | 100000 | 8 | 19 | 2500000 | 4000000 | Translated by ChatGPT 5