#P10637. BZOJ4262 Sum

    ID: 12111 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树O2优化吉司机线段树 segment tree beats

BZOJ4262 Sum

Problem Description

Given an integer sequence aia_i of length 10510^5, you need to answer tt queries. Each query provides four values l1,l2,r1,r2l_1, l_2, r_1, r_2, and you need to compute:

$$\sum_{l \in [l_1,r_1]} \sum_{r \in [l_2,r_2]} (\max_{i \in [l,r]} a_i-\min_{i\in [l,r]} a_i)$$

You do not have to process the queries online.

In this problem, the sequence aia_i is generated by the following code:

const int mod = 1e9;
long long fst = 1023, sec = 1025;
for (int i = 1; i <= 100000; i++) {
	a[i] = fst ^ sec;
	fst = fst * 1023 % mod;
	sec = sec * 1025 % mod;
}

Input Format

The first line contains an integer tt, indicating the number of queries.

The next tt lines each contain four integers l1,r1,l2,r2l_1, r_1, l_2, r_2.

Output Format

Output tt lines in total. Each line contains one number Sum\text{Sum}, which is the answer.

4
1 3 5 7
2 4 6 8
1 1 9 9
9 9 1 1
9322587654
9025304064
1065645568
0

Hint

Constraints: 1t400001\leq t\leq 40000, 1l1r11051\leq l_1 \leq r_1\leq 10^5, 1l2r21051\leq l_2 \leq r_2\leq 10^5.

Translated by ChatGPT 5