-
Notifications
You must be signed in to change notification settings - Fork 9
/
GIVEAWAY - Give Away.cpp
58 lines (58 loc) · 1.42 KB
/
GIVEAWAY - Give Away.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define mx 500005
vector<int> block[710];
int len;
int arr[mx];
void Update(int id, int val)
{
int b = id/len;
int idx = lower_bound(block[b].begin(), block[b].end(),arr[id]) - block[b].begin();
block[b][idx] = arr[id] = val;
sort(block[b].begin(), block[b].end());
}
void Query(int l, int r, int x)
{
int ans = 0;
int L = l/len, R = r/len;
if(L==R){
for(int i=l; i<=r; i++)
if(arr[i]>=x) ans++;
}
else{
for(int i = L*len + len-1; i>=l; i--)
if(arr[i]>=x)ans++;
for(int i = L+1; i<R; i++)
ans+=( block[i].size() - (lower_bound(block[i].begin(), block[i].end(),x) - block[i].begin()) );
for(int i = R*len; i<=r; i++)
if(arr[i]>=x)ans++;
}
printf("%d\n", ans);
}
int main()
{
int n,q;
scanf("%d",&n);
len = sqrt(n)+1;
for(int i=0; i<n; i++){
scanf("%d",&arr[i]);
block[ i/len ].push_back(arr[i]);
}
for(int i=0; i<=len; i++)
sort(block[i].begin(), block[i].end());
scanf("%d",&q);
int typ;
while(q--){
scanf("%d",&typ);
if(typ==0){
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
Query(l-1, r-1,x);
}
else{
int l, v;
scanf("%d%d",&l,&v);
Update(l-1,v);
}
}
}