-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathF_RangeUpdatePointQuery.cpp
More file actions
78 lines (63 loc) · 1.29 KB
/
F_RangeUpdatePointQuery.cpp
File metadata and controls
78 lines (63 loc) · 1.29 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
#include "bits/stdc++.h"
using i64 = long long;
void solve()
{
int n, q;
std::cin >> n >> q;
std::set<int> pos;
std::vector<int> a(n);
for (int i = 0; i < n; i++)
{
std::cin >> a[i];
if (a[i] / 10 > 0)
pos.emplace(i);
}
auto sum = [&](int x)
{
int sum = 0;
while (x != 0)
{
sum += x % 10;
x /= 10;
}
return sum;
};
while (q--)
{
int t;
std::cin >> t;
if (t == 1)
{
int l, r;
std::cin >> l >> r;
l--, r--;
auto start = pos.lower_bound(l);
auto end = pos.upper_bound(r);
std::vector<int> rem;
for (auto it = start; it != end; it++)
{
a[*it] = sum(a[*it]);
if (a[*it] / 10 == 0)
rem.emplace_back(*it);
}
for (auto del : rem)
pos.erase(del);
}
else
{
int x;
std::cin >> x;
std::cout << a[x - 1] << "\n";
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--)
solve();
return 0;
}