# bzoj 3211 分类： bzoj 2015-08-07 18:00 8人阅读 评论(0) 收藏

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <iostream>
#include <algorithm>

{
char c; int flag = 1;
while((c = getchar()) < '0' || c > '9')
if(c == '-') flag *= -1;
x = c - '0';
while((c = getchar()) >= '0' && c <= '9')
x = (x<<3) + (x<<1) + (c-'0');
x *= flag;
return;
}
template<class Num>void write(Num x)
{
if(x < 0) putchar('-'), x = -x;
static char s[20];int sl = 0;
while(x) s[sl++] = x%10 + '0',x /= 10;
if(!sl) {putchar('0');return;}
while(sl) putchar(s[--sl]);
}
const int maxn = 1e5 + 5;

int n , m, a[maxn];

int max[maxn<<2];
long long sum[maxn<<2];

#define L(x)  (x<<1)
#define R(x)  ((x<<1)|1)
long long query(int l,int r,int ll,int rr,int si)
{
if(l == ll && r == rr)
return sum[si];
else
{
int mid = (ll+rr)>>1;

if(r <= mid)
return query(l,r,ll,mid,L(si));
else if(l > mid)
return query(l,r,mid+1,rr,R(si));
else
return query(l, mid,ll,mid,L(si)) + query(mid+1,r,mid+1,rr,R(si));
}
}
void update(int x)
{
sum[x] = sum[L(x)] + sum[R(x)];
max[x] = std::max(max[L(x)], max[R(x)]);
}
void build(int ll,int rr,int si)
{
if(ll == rr)
sum[si] = max[si] = a[ll];
else
{
int mid = (ll+rr)>>1;

build(ll,mid,L(si));

build(mid+1,rr,R(si));

update(si);
}
}
void change(int l,int r,int ll,int rr,int si)
{
if(max[si] <= 1)return;

if(ll == rr)
{
max[si] = sqrt(max[si]);
sum[si] = max[si];
}
else
{
int mid = (ll+rr)>>1;
if(r <= mid)
change(l,r,ll,mid,L(si));
else if(l > mid)
change(l,r,mid+1,rr,R(si));
else
{
change(l,mid,ll,mid,L(si));
change(mid+1,r,mid+1,rr,R(si));
}
update(si);
}
}
#undef L
#undef R

int main()
{
#ifndef ONLINE_JUDGE
freopen("3211.in","r",stdin);
freopen("3211.out","w",stdout);
#endif

for(int i = 1; i <= n; i++) read(a[i]);

build(1, n, 1);

while(m--)
{
int op, l, r;

switch(op)
{
case 1:
write(query(l, r, 1, n, 1)), puts("");
break;
case 2:
change(l, r, 1, n, 1);
break;
}
}

#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}

posted @ 2015-08-07 18:00    阅读(100)  评论(0编辑  收藏  举报