0pts求调
查看原帖
0pts求调
470590
LikAzusa_楼主2024/10/10 19:24

怎么都能过样例,#1-#10WA,#11-#20RE

#include <bits/stdc++.h>
#define int long long

using namespace std;

inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while(c > '9' || c < '0') {if(c == '-') f = -1; c = getchar();}
	while(c <= '9' && c >= '0') {x = x * 10 + c - '0'; c = getchar();}
	return x * f;
}

const int mod = 4294967296;
const int maxn = 2e5 + 10;
int n, m;
int a[maxn];
struct Node
{
	int l, r;
	int sum;
	int lcm;
	#define lson (id<<1)
	#define rson (id<<1|1)
}t[maxn<<2];

int _lcm(int x, int y) {return x * y / __gcd(x, y);}
void update(int id)
{
	t[id].sum = t[lson].sum + t[rson].sum;
	t[id].lcm = min((__int128)2e18, (__int128)_lcm(t[lson].lcm, t[rson].lcm));
}
void build(int id, int L, int R)
{
	t[id].l = L; t[id].r = R;
	if(L == R)
	{
		t[id].sum = t[id].lcm = a[L];
		return;
	}
	int mid = (L + R) >> 1;
	build(lson, L, mid);
	build(rson, mid+1, R);
	update(id);
}

void change(int id, int L, int R, int x)
{
	if(!(x % t[id].lcm)) return;
	if(t[id].l == t[id].r)
	{
		t[id].sum = t[id].lcm = __gcd(t[id].lcm, x);
		return;
	}
	int mid = t[id].l + t[id].r >> 1;
	if(L <= mid) change(lson, L, mid, x);
	if(R > mid) change(rson, mid+1, R, x);
	update(id);
}

int query(int id, int L, int R)
{
	if(t[id].l >= L && t[id].r <= R) return t[id].sum;
	int mid = t[id].l + t[id].r >> 1;
	int ans = 0;
	if(L <= mid) ans += query(lson, L, R);
	if(R > mid) ans += query(rson, L, R);
	return ans;
}

signed main()
{
	n = read(); m = read();
	for(int i = 1; i <= n; i++) a[i] = read();
	build(1, 1, n);
	while(m--)
	{
		int op = read(), l = read(), r = read();
		if(op == 1)
		{	
			int x = read();
			change(1, l, r, x);
		}
		else
		{
			cout << query(1, l, r) % mod << endl;
		}
	}
	return 0;
}

2024/10/10 19:24
加载中...