问题 E: Or

内存限制:512 MB 时间限制:6 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

DDOSvoid is learning about bitwise operations and has come across an interesting problem.

You are given two sequences, ��ai and ��bi, both of length n. Additionally, there are m queries. In each query, you are given an interval [�,�][l,r]. Your task is to calculate the bitwise OR operation on the following integers:��,��+��+1,��+��+1+��+2,⋯,��+1+��+2,��+1+��+2+��+3,⋯,��al,al+bl+1,al+bl+1+bl+2,,al+1+bl+2,al+1+bl+2+bl+3,,ar. In other words, you need to evaluate ⨁�=��⨁�=��(��+∑�=�+1���)i=lrj=ir(ai+k=i+1jbk). The symbol  represents the bitwise OR operation.

输入格式

The first line of the input contains a single integer T, indicating the number of test cases.

In each test case:

The first line contains to integers �,�(1≤�≤105,1≤�≤106)n,m(1n105,1m106).

The second line contains n integers ��(0≤��≤5×108)ai(0ai5×108).

The third line contains n integers ��(0≤��≤5000)bi(0bi5000).

The next m lines, each line contains two integers �,�(1≤�≤�≤�)l,r(1lrn).

It is guaranteed that in all test cases, ∑�≤105,∑�≤106n105,m106.

输出格式

To simply the output, we use ����ansi to represent the answer to the i-th query and ����=233,�=998244353base=233,P=998244353.

In each test case you just need to output an integer (∑�=1�����×�����)mod�(i=1mansi×basei)modP.

输入样例 复制

1
5 1
1 2 3 4 5
1 1 1 1 1
2 4

输出样例 复制

1631

数据范围与提示

For query [2,4][2,4], you need to calculate the bitwise OR operation on the following integers, �2,�2+�3,�2+�3+�4,�3,�3+�4,�4a2,a2+b3,a2+b3+b4,a3,a3+b4,a4

分类标签