#include<bits/stdc++.h>
using namespace std;
#define DISABLE_MMAP
#define gc getchar_unlocked
#define pc putchar_unlocked
#define int unsigned
#define ctz __builtin_ctz
const int N = 1000010, M = 5000010;
int h[N], to[M], nxt[M], id[M], idx, n, m; unsigned ans[M];
void add(int a, int b, int c) {to[++idx] = b; id[idx] = c; nxt[idx] = h[a]; h[a] = idx;}
const int SIZE=(1<<20)+1;
char buf[SIZE],*p1=buf,*p2=buf;
char buffer[SIZE];
int op1=-1;
const int op2=SIZE-1; char s[25];
inline char readchar() {
if(p1!=p2) {
return *p1++;
}
return p1==(p2=(p1=buf)+fread(buf,1,SIZE-1,stdin))?EOF:*p1++;
}
inline void flush() {
fwrite(buffer,1,op1+1,stdout),op1=-1;
}
inline void writechar(const char &x) {
if(op1==op2) flush();
buffer[++op1]=x;
}
#ifndef ONLINE_JUDGE
#define readchar getchar
#endif
#define putchar writechar
inline int Read() {
int c=readchar(),x=0;
while(c<=32) {
c=readchar();
}
for(; ('0'<=c && c<='9'); c=readchar()) {
x=x*10+c-'0';
}
return x;
}
inline void write(int x) {
if(x<0) {
writechar('-'),x=-x;
}
char s[25];
int n=0;
while(x || !n) {
s[n++]='0'+x%10,x/=10;
}
while(n--) {
writechar(s[n]);
}
}
inline signed gcd(signed a,signed b) {
signed az = ctz(a), bz = ctz(b), z = (az > bz) ? bz : az, t; b >>= bz;
while(a) a >>= az, t = a - b, az = ctz(t), b = min(a, b), a = t < 0ll ? -t : t;
return b << z;
}
int tt, a[N], b[N], c[N]; unsigned f[N], g[N], H[N];
int ask(int x) {return f[x] + g[x] * (tt - H[x]);}
signed main() {
n = Read(), m = Read(); for(int i = 1; i <= n; i++) {
char c=readchar();
while(c<=32) {
c=readchar();
}
for(; ('0'<=c && c<='9'); c=readchar()) {
a[i]=a[i]*10+c-'0';
}
}
for(int i = 1; i <= n; i++) {
char c=readchar();
while(c<=32) {
c=readchar();
}
for(; ('0'<=c && c<='9'); c=readchar()) {
b[i]=b[i]*10+c-'0';
}
}
for(int i = 1; i <= n; i++) {
char ch=readchar();
while(ch<=32) {
ch=readchar();
}
for(; ('0'<=ch && ch<='9'); ch=readchar()) {
c[i]=c[i]*10+ch-'0';
}
}
for(int i = 1; i <= m; i++) {
int l = 0, r = 0;
char c=readchar();
while(c<=32) {
c=readchar();
}
for(; ('0'<=c && c<='9'); c=readchar()) {
l=l*10+c-'0';
}
c=readchar();
while(c<=32) {
c=readchar();
}
for(; ('0'<=c && c<='9'); c=readchar()) {
r=r*10+c-'0';
}
to[++idx] = l - 1, id[idx] = i, nxt[idx] = h[r]; h[r] = idx;
}
for(int i = 1; i <= n; i++) {
int pos = i;
for(; --pos; ) {
int x = a[pos] & a[pos + 1], y = b[pos] | b[pos + 1], z = gcd(c[pos], c[pos + 1]);
if(x == a[pos] && y == b[pos] && z == c[pos]) break;
a[pos] = x, b[pos] = y, c[pos] = z;
}
f[i] = f[i - 1] + g[i - 1] * (tt - H[i - 1]);
for(; ++pos <= i;) f[pos] = f[pos] + g[pos] * (tt - H[pos]), g[pos] = g[pos - 1] + a[pos] * b[pos] * c[pos], H[pos] = tt;
tt++; int tmp = f[i] + g[i] * (tt - H[i]); for(int j = h[i]; j; j = nxt[j]) ans[id[j]] = tmp - f[to[j]] - g[to[j]] * (tt - H[to[j]]);
}
for(int i = 1; i <= m; i++) {
int C=0;
while(ans[i] || !C) {
s[C++]='0'+ans[i]%10,ans[i]/=10;
}
while(C--) {
writechar(s[C]);
}
writechar('\n');
}
flush();
return 0;
}
/*
10 3
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 10
1 10
1 10
*/剪贴板
剪贴板 w51s778g
剪贴板信息
剪贴板信息
- 收录
- 更新