暴力 O2 91pts 求调
查看原帖
暴力 O2 91pts 求调
545310
YXD123456789楼主2023/9/24 20:52

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 1e5 + 2;
int n,m;
int type;
int a[N];
int x,y,z;
inline int read()
{
	int x,f;
	char ch;
	x = 0;
	f = 1;
	ch = getchar();
	while(ch < '0' || ch > '9')
	{
		ch == '-' ? f = -1 : ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		x = (x << 3) + (x << 1) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}
inline void write(ll x)
{
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
inline void kkk1()
{
	x = read();
	y = read();
	z = read();
	if(z == 1)
	{
		return ;
	}
	if(z == 2)
	{
		for(register int i = x;i <= y ;i = -(~ i))
		{
			a[i] = a[i] & 1 ? a[i] : a[i] >> 1;
		}
		return ;
	}
	for(int i = x;i <= y ;i = -(~ i))
	{
		a[i] = a[i] % z == 0 ? a[i] / z : a[i];
	}
}
inline void kkk2()
{
	ll sum = 0ll;
	x = read();
	y = read();
	for(register int i = x;i <= y;i = - (~ i))
	{
		sum += a[i];
	}
	write(sum);
	putchar('\n');
}
signed main()
{
	n = read();m = read();
	for(register int i = 1;i <= n;i = -(~ i))
	{
		a[i] = read();
	}
	for(register int i = 1;i <= m;i = -(~ i))
	{
		type = read();
		type & 1 == 1 ? kkk1() : kkk2();
	}
	return 0;
}
2023/9/24 20:52
加载中...