luogu#P8911. [RC-06] Minimum and Maximum
[RC-06] Minimum and Maximum
Background
Due to Luogu limitations, the testdata for this problem has been reduced. For the full set of testdata, please go to InfOJ.
Problem Description
Given a sequence of length , .
There are queries. Each query gives four positive integers $L_1,R_1,L_2,R_2\ (1\le L_1\le R_1\le 4000,1\le L_2\le R_2\le 4000)$. You need to count how many intervals satisfy that, among , the maximum value lies in and the minimum value lies in .
The number of queries is very large, so the queries are generated inside the program. Please read the code in the Hint section by yourself.
Input Format
The first line contains two positive integers .
The next line contains positive integers .
The next line contains three positive integers , which are the parameters of the data generator. You do not need to understand the detailed running process of the data generator. You only need to know that if the queries are generated correctly, then must hold.
Output Format
Let the answer to the -th query be . Output one line with one integer, the value of .
5 5
2 4 1 3 5
1 5 1145141919810
24
10 20000000
1 3 4 10 5 5 2 7 10 7
1 10 23333333333333333
548722417
Hint
Explanation for Sample 1
For the five queries, are respectively , and the answers are respectively .
Output $(1\times 15)\ \mathrm{xor}\ (2\times 1)\ \mathrm{xor}\ (3\times 1)\ \mathrm{xor}\ (4\times 2)\ \mathrm{xor}\ (5\times 6)=24$.
Sample Program
Below is the sample program we provide. You can directly write your program based on it.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace Generator{
typedef unsigned long long ull;
typedef __uint128_t L;
ull seed;
int p,q;
struct FastMod {
ull b, m;
FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
ull reduce(ull a) {
ull q = (ull)((L(m) * a) >> 64);
ull r = a - q * b; // can be proven that 0 <= r < 2*b
return r >= b ? r - b : r;
}
}F(2);
void init(){
cin>>p>>q>>seed;//read p,q,seed
assert(p!=q);
F=FastMod(q-p+1);
}
unsigned long long rd () {
seed ^= (seed << 13);
seed ^= (seed >> 7);
seed ^= (seed << 17);
return seed;
}
void getlr(int &l1,int &r1,int &l2,int &r2){
//pass l1,r1,l2,r2 as parameters to get one query
l1=F.reduce(rd())+p;
r1=F.reduce(rd())+p;
l2=F.reduce(rd())+p;
r2=F.reduce(rd())+p;
if(l1>r1)swap(l1,r1);
if(l2>r2)swap(l2,r2);
}
}
int n,m,a[100005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
Generator::init();
long long xorsum=0;
for(int i=1,l1,r1,l2,r2;i<=m;i++){
Generator::getlr(l1,r1,l2,r2);
long long ans=/*ans stores your answer*/;
xorsum^=ans*i;
}
cout<<xorsum;
}
Constraints
This problem has four subtasks. Subtask 1 has a time limit of seconds, and the other subtasks have a time limit of seconds.
All testdata satisfies: ,,,,.
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): No special constraints.
Translated by ChatGPT 5