308679: CF1556E. Equilibrium
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Equilibrium
题意翻译
给出两个长度为 $n$ 的正整数序列 $a$ 和 $b$ 你需要回答 $q$ 次询问,每次给出 $[l,r]$,问进行以下操作的最少次数使得 $\forall i\in [l,r] \,,a_i=b_i$,或报告无解 询问之间互相独立 一次操作定义为选出一个长度为 $k$($k$ 是偶数)的正整数序列 $pos$,满足 $l\le pos_1<pos_2<\ldots<pos_{k-1}<pos_k\le r$,将 $a_{pos_1},a_{pos_3},\ldots,a_{pos_{k-1}}$ 加一,将 $b_{pos_2},b_{pos_4},\ldots,b_{pos_k}$ 加一题目描述
![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1556E/82dac8544603b5a29531fd9591e7750ab2f3a8ad.png)William has two arrays $ a $ and $ b $ , each consisting of $ n $ items. For some segments $ l..r $ of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each $ i $ from $ l $ to $ r $ holds $ a_i = b_i $ . To perform a balancing operation an even number of indices must be selected, such that $ l \le pos_1 < pos_2 < \dots < pos_k \le r $ . Next the items of array a at positions $ pos_1, pos_3, pos_5, \dots $ get incremented by one and the items of array b at positions $ pos_2, pos_4, pos_6, \dots $ get incremented by one. William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently.输入输出格式
输入格式
The first line contains a two integers $ n $ and $ q $ ( $ 2 \le n \le 10^5 $ , $ 1 \le q \le 10^5 $ ), the size of arrays $ a $ and $ b $ and the number of segments. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ $ (0 \le a_i \le 10^9) $ . The third line contains $ n $ integers $ b_1, b_2, \dots, b_n $ $ (0 \le b_i \le 10^9) $ . Each of the next $ q $ lines contains two integers $ l_i $ and $ r_i $ $ (1 \le l_i < r_i \le n) $ , the edges of segments.
输出格式
For each segment output a single number — the minimal number of balancing operations needed or "-1" if it is impossible to equalize segments of arrays.
输入输出样例
输入样例 #1
8 5
0 1 2 9 3 2 7 5
2 2 1 9 4 1 5 8
2 6
1 7
2 4
7 8
5 8
输出样例 #1
1
3
1
-1
-1