forked from sdssudhu/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGSS4.cpp
More file actions
94 lines (71 loc) · 1.35 KB
/
Copy pathGSS4.cpp
File metadata and controls
94 lines (71 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Can you answer these queries IV
#include<bits/stdc++.h>
using namespace std;
long long ar[100001];
long long tree[1000000],tree2[1000000];
void build(int node,int l,int r)
{
if(l>r) return;
if(l==r)
{
tree[node]=ar[l];
return;
}
build(node*2,l,(l+r)/2);
build(node*2+1,(l+r)/2+1,r);
tree[node]=tree[node*2]+tree[node*2+1];
}
void update(int node,int l,int r,int i,int j)
{
if(j<l || i>r || l>r) return;
if(tree[node]==r-l+1)
return;
if(l==r)
{
tree[node]=sqrt(tree[node]);
return;
}
update(node*2,l,(l+r)/2,i,j);
update(node*2+1,(l+r)/2+1,r,i,j);
tree[node]=tree[node*2]+tree[node*2+1];
}
long long query(int node,int l,int r,int i,int j)
{
if(j<l || i>r || l>r) return 0;
if(i<=l && j>=r)
return tree[node];
long long q1=query(node*2,l,(l+r)/2,i,j);
long long q2=query(node*2+1,(l+r)/2+1,r,i,j);
return q1+q2;
}
int main()
{
int n,m,i,j,ch,l,r,k=1;
while(scanf("%d",&n)!=EOF)
{
printf("Case #%d:\n",k);
++k;
for(i=1;i<=n;++i)
scanf("%lld",&ar[i]);
build(1,1,n);
scanf("%d",&m);
while(m>0)
{
scanf("%d %d %d",&ch,&l,&r);
if(l>r)
{
swap(l,r);
}
if(ch==0)
{
update(1,1,n,l,r);
}
else
{
printf("%lld\n",query(1,1,n,l,r));
}
--m;
}
}
return 0;
}