-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelpAshu(hackerearth).cpp
More file actions
76 lines (71 loc) · 929 Bytes
/
HelpAshu(hackerearth).cpp
File metadata and controls
76 lines (71 loc) · 929 Bytes
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
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,fTree[100001],a[100001];
void update(int x,int type)
{
for(;x<=n;x+=x&-x)
{
fTree[x]+=type;
}
}
ll query(int x)
{
ll ans=0;
for(;x>0;x-=x&-x)
{
ans+=fTree[x];
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
ll temp,q,i,type,L,R;
for(i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]&1)
update(i,1);
else
update(i,0);
}
cin>>q;
ll ind;
for(i=0;i<q;i++)
{
cin>>type;
if(type==0)
{
cin>>ind>>temp;
if(a[ind]&1)
{
if(!(temp&1))
{
a[ind]=2;
update(ind,-1);
}
}
else
{
if(temp&1)
{
a[ind]=3;
update(ind,1);
}
}
}
else
{
cin>>L>>R;
ll ans=query(R);
if(L-1>0)
ans-=query(L-1);
if(type==2)
cout<<ans<<endl;
else
cout<<(R-L+1)-ans<<endl;
}
}
}