-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoneAgeProblem.cpp
More file actions
59 lines (56 loc) · 1.16 KB
/
StoneAgeProblem.cpp
File metadata and controls
59 lines (56 loc) · 1.16 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
// https://codeforces.com/problemset/problem/1679/B
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
#include <cstdint>
#include <map>
#include <unordered_map>
#define ll long long
#define u64 uint64_t
#define i64 int64_t
using namespace std;
void solveCase() {
int len, lenq;
cin >> len >> lenq;
ll sum = 0;
int a[len];
bool def[len];
for (int i = 0; i < len; i++) {
int input;
cin >> input;
a[i] = input;
sum += input;
}
unordered_map<int, bool> vis;
int r_all = 0;
for (int q = 0; q < lenq; q++) {
int t;
cin >> t;
if (t == 1) {
int i, x;
cin >> i >> x;
i--;
sum += (vis[i] || !r_all) ? x-a[i] : x-r_all;
a[i]= x;
vis[i] = true;
} else {
cin >> r_all;
sum = (ll)len*r_all;
vis.clear();
}
cout << sum << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nC = 1;
// cin >> nC;
while (nC--) {
solveCase();
}
return 0;
}