3211: 花神游历各国

3211: 花神游历各国

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 2438  Solved: 908
[ Submit][ Status][ Discuss]

Description

Input

Output

每次x=1时,每行一个整数,表示这次旅行的开心度

Sample Input

4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output

101

11

11

HINT

对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9


Source

[ Submit][ Status][ Discuss]

线段树维护区间和
对于修改,暴力搞一下每个数就行(因为是根号,没几下就完了)


一开始没注意到非负数???所以1or0停止
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;
const int T = 6;
typedef long long LL;

int n,m;
bool Mark[maxn*T];
LL c[maxn*T];

void Insert(int o,int l,int r,int pos,int x)
{
	if (l == r) {
		c[o] = x;
		if (c[o] <= 1) Mark[o] = 1;
		return;
	}
	int mid = (l + r) >> 1;
	if (pos <= mid) Insert(o<<1,l,mid,pos,x);
	else Insert(o<<1|1,mid+1,r,pos,x);
	c[o] = c[o<<1] + c[o<<1|1];
	if (Mark[o<<1] && Mark[o<<1|1]) Mark[o] = 1;
}

LL Query(int o,int l,int r,int ql,int qr)
{
	if (ql <= l && r <= qr) return c[o];
	int mid = (l + r) >> 1;
	LL ret = 0;
	if (ql <= mid) ret += Query(o<<1,l,mid,ql,qr);
	if (qr > mid) ret += Query(o<<1|1,mid+1,r,ql,qr);
	return ret;
}

void Modify(int o,int l,int r,int ml,int mr)
{
	if (Mark[o]) return;
	if (l == r) {
		c[o] = floor(sqrt(c[o]));
		if (c[o] <= 1) Mark[o] = 1;
		return;
	}
	int mid = (l + r) >> 1;
	if (ml <= mid) Modify(o<<1,l,mid,ml,mr);
	if (mr > mid) Modify(o<<1|1,mid+1,r,ml,mr);
	c[o] = c[o<<1] + c[o<<1|1];
	if (Mark[o<<1] && Mark[o<<1|1]) Mark[o] = 1;
}

int getint()
{
	int ch = getchar();
	int ret = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9')
		ret = ret*10 + ch - '0',ch = getchar();
	return ret;
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	n = getint();
	for (int i = 1; i <= n; i++) {
		int x = getint();
		Insert(1,1,n,i,x);
	}
	m = getint();
	while (m--) {
		int typ,l,r;
		typ = getint();
		l = getint();
		r = getint();
		if (typ == 1) printf("%lld\n",Query(1,1,n,l,r));
		else Modify(1,1,n,l,r);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值