forked from Vishal1003/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 2
/
D-NumberOfDifferentOnSegment.cpp
74 lines (72 loc) 路 2.04 KB
/
D-NumberOfDifferentOnSegment.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
#define pc putchar
#define gc getchar
#define gcu getchar_unlocked
#define fi first
#define se second
#define pb push_back
#define mod ((ll)1e9 + 7)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//===============================================================================================
int n, m, base = 1;
int a[300009][49], ans[49];
void obliczans(int v, int l, int r, int x, int y);
//===============================================================================================
int main()
{
scanf("%d %d", &n, &m);
while (base < n)
base <<= 1;
for (int i = 0, temp; i < n; i++)
{
scanf("%d", &temp);
a[base + i][temp]++;
}
for (int i = base - 1; i; i--)
for (int j = 1; j <= 40; j++)
a[i][j] = a[i * 2][j] + a[i * 2 + 1][j];
for (int i = 0, tempa, tempb, tempc; i < m; i++)
{
scanf("%d %d %d", &tempa, &tempb, &tempc);
if (tempa == 1)
{
memset(ans, 0, sizeof ans);
obliczans(1, 0, base - 1, tempb - 1, tempc - 1);
tempa = 0;
for (int j = 1; j <= 40; j++)
if (ans[j])
tempa++;
printf("%d\n", tempa);
}
else
{
tempb += base - 1;
memset(a[tempb], 0, sizeof a[tempb]);
a[tempb][tempc]++;
tempb >>= 1;
while (tempb)
{
for (int j = 1; j <= 40; j++)
a[tempb][j] = a[tempb * 2][j] + a[tempb * 2 + 1][j];
tempb >>= 1;
}
}
}
}
//===============================================================================================
void obliczans(int v, int l, int r, int x, int y)
{
if (l > y || r < x)
return;
if (l >= x && r <= y)
{
for (int i = 1; i <= 40; i++)
if (a[v][i])
ans[i] = 1;
return;
}
obliczans(v * 2, l, (l + r) / 2, x, y);
obliczans(v * 2 + 1, (l + r) / 2 + 1, r, x, y);
}