# 3211: 花神游历各国

## 3211: 花神游历各国

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

4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

101

11

11

## Source

[Submit][Status][Discuss]

#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;
}


#### BZOJ 3211(花神游历各国-线段树区间开方)

2013-05-28 12:32:27

#### 题解【luoguP4145 上帝造题的七分钟2（花神游历各国）】

2018-03-04 18:44:14

#### BZOJ 3211 花神游历各国 树状数组+并查集

2014-10-10 14:22:59

#### bzoj3211 花神游历各国

2016-03-28 21:59:57

#### BZOJ-3211花神游历各国 并查集+树状数组

2015-12-05 21:56:54

#### 【BZOJ3211】花神游历各国

2015-04-10 07:29:53

#### |BZOJ 3211|树状数组|并查集|花神游历各国

2017-02-25 17:09:27

#### BZOJ[3211]花神游历各国 树状数组+并查集

2017-08-20 21:52:29

#### 【bzoj3211】【花神游历各国】【线段树+并查集】

2015-09-26 14:31:14

#### BZOJ3038 && BZOJ3211 上帝造题的七分钟2 && 花神游历各国 (线段树 + 开方标记)

2015-08-23 13:47:04