题解
2026-09-09 13:26:04
发布于:山西
5阅读
0回复
0点赞
代码:
#include<bits/stdc++.h>
#define int unsigned int
using namespace std;
namespace FastIO {
char buf[1 << 9], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh = '\n';
int p, p3 = -1;
void read() {}
void print() {}
inline int getc() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 9, stdin), p1 == p2) ? EOF : *p1++;
}
inline void flush() {
fwrite(buf2, 1, p3 + 1, stdout), p3 = -1;
}
template <typename T, typename... T2>
inline void read(T &x, T2 &...oth) {
int f = 0;
x = 0;
char ch = getc();
while (!isdigit(ch)) {
if (ch == '-') f = 1;
ch = getc();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ '0');
ch = getc();
}
x = f ? -x : x;
read(oth...);
}
template <typename T, typename... T2>
inline void print(T x, T2... oth) {
if (p3 > 1 << 20)
flush();
if (x < 0)
buf2[++p3] = 45, x = -x;
do {
a[++p] = x % 10 + 48;
} while (x /= 10);
do {
buf2[++p3] = a[p];
} while (--p);
buf2[++p3] = hh;
print(oth...);
}
}
#define read FastIO::read
#define print FastIO::print
const int N = 1e6 + 10;
const int M = 5e6 + 10;
int a[N], b[N], c[N], l[M], r[M];
int tot[N], id[M], sum[N], num[N];
int tim[N];
int n, m, ans[M];
int gcd(int a, int b){
return !b ? a : gcd(b, a % b);
}
signed main(){
read(n); read(m);
for(register int i = 1; i <= n; ++ i) read(a[i]);
for(register int i = 1; i <= n; ++ i) read(b[i]);
for(register int i = 1; i <= n; ++ i) read(c[i]);
for(register int i = 1; i <= m; ++ i) read(l[i]), read(r[i]), tot[r[i]] ++;
for(register int i = 1; i <= n; ++ i) tot[i] += tot[i - 1];
for(register int i = 1; i <= m; ++ i) id[tot[r[i] - 1] ++ ] = i;
for(register int i = 1, j = 0; i <= n; ++ i){
register int p = i;
while(-- p){
register int A = a[p] & a[p + 1], B = b[p] | b[p + 1], C = gcd(c[p], c[p + 1]);
if(A == a[p] && B == b[p] && C == c[p]) break;
a[p] = A, b[p] = B, c[p] = C;
}
sum[i] = sum[i - 1] + num[i - 1] * (i - 1 - tim[i - 1]);
for(; ++ p <= i; ){
sum[p] += num[p] * (i - 1 - tim[p]);
tim[p] = i - 1;
num[p] = num[p - 1] + a[p] * b[p] * c[p];
}
register int tmp = sum[i] + num[i] * (i - tim[i]);
for(; j < tot[i - 1]; ++ j){
ans[id[j]] = tmp - sum[l[id[j]] - 1] - num[l[id[j]] - 1] * (i - tim[l[id[j]] - 1]);
}
}
for(register int i = 1; i <= m; ++ i) print(ans[i]);
FastIO :: flush();
}
这里空空如也







有帮助,赞一个