3211: 花神游历各国
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 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
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
11
11
HINT
对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9
Source
#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;
}