Note: The only difference between the easy and the hard version is the constraints on nnn and mim_imi.
Since Little Horse gets a golden prize in a programming contest, many companies send offers to him. There are
nnn companies, and the
iii-th company has
mim_imi available jobs. To get an offer from a company, you need to be qualified for the job.
How to be qualified? The company will test your "three quotients":
IQ (Intelligence Quotient),
EQ (Emotional Quotient), and
AQ (Adversity Quotient). Each job has three lower limits of the three quotients respectively. If all of your
IQ,
EQ, and
AQ are no less than the corresponding lower limits, you are qualified for the job. As long as you are qualified for at least one job in a company, the company will send an offer to you.
Little Horse's three quotients are all high enough, so all the companies send offers to him. But Little Horse has qqq friends that worry about their jobs. Given the value of IQ, EQ and AQ of each friend, Little Horse wants to know how many companies will send offers to each friend.
In this problem, the IQ, EQ, and AQ of these qqq friends are generated as below.
First, register an mt19937\texttt{mt19937}mt19937 random engine rng\texttt{rng}rng with the seed\texttt{seed}seed and a uniform integer distribution object.
#include <random>
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1,400);
Then, the value of
IQ,
EQ, and
AQ are generated as follows.
int lastans=0;
for (int i=1;i<=q;i++)
{
int IQ=(u(rng)^lastans)%400+1; // The IQ of the i-th friend
int EQ=(u(rng)^lastans)%400+1; // The EQ of the i-th friend
int AQ=(u(rng)^lastans)%400+1; // The AQ of the i-th friend
lastans=solve(IQ,EQ,AQ); // The answer to the i-th friend
}