mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 12:26:49 +00:00
F - Operations on a Matrix
https://atcoder.jp/contests/abc253/submissions/35160697
This commit is contained in:
parent
a2b5c850ee
commit
2204c5110c
103
AtCoder/ABC253/F/F.cpp
Normal file
103
AtCoder/ABC253/F/F.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 2e5 + 5;
|
||||||
|
|
||||||
|
int n, m, q, idx, cnt, lst[N];
|
||||||
|
long long c[N], val[N], ans[N];
|
||||||
|
std::vector<std::tuple<int, int, int>> changes;
|
||||||
|
std::vector<std::tuple<int, int, bool>> queries[N];
|
||||||
|
|
||||||
|
int lowbit(int x) {
|
||||||
|
return x & -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(int x, int y) {
|
||||||
|
for (; x <= m; x += lowbit(x)) c[x] += y;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long sum(int x) {
|
||||||
|
long long res = 0;
|
||||||
|
for (; x; x -= lowbit(x)) res += c[x];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m >> q;
|
||||||
|
|
||||||
|
changes.emplace_back(1, n, 0);
|
||||||
|
|
||||||
|
for (int i = 1; i <= q; i++) {
|
||||||
|
int op;
|
||||||
|
|
||||||
|
cin >> op;
|
||||||
|
|
||||||
|
switch (op) {
|
||||||
|
case 1: {
|
||||||
|
int l, r, x;
|
||||||
|
|
||||||
|
cin >> l >> r >> x;
|
||||||
|
|
||||||
|
changes.emplace_back(l, r, x);
|
||||||
|
idx++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2: {
|
||||||
|
int i, x;
|
||||||
|
|
||||||
|
cin >> i >> x;
|
||||||
|
|
||||||
|
lst[i] = idx;
|
||||||
|
val[i] = x;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3: {
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
cin >> i >> j;
|
||||||
|
|
||||||
|
ans[++cnt] = val[i];
|
||||||
|
queries[lst[i]].emplace_back(j, cnt, false);
|
||||||
|
queries[idx].emplace_back(j, cnt, true);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < changes.size(); i++) {
|
||||||
|
int l, r, x;
|
||||||
|
|
||||||
|
std::tie(l, r, x) = changes[i];
|
||||||
|
|
||||||
|
add(l, x);
|
||||||
|
add(r + 1, -x);
|
||||||
|
|
||||||
|
for (auto query : queries[i]) {
|
||||||
|
int pos, id, type;
|
||||||
|
|
||||||
|
std::tie(pos, id, type) = query;
|
||||||
|
|
||||||
|
if (type) ans[id] += sum(pos);
|
||||||
|
else ans[id] -= sum(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= cnt; i++) {
|
||||||
|
cout << ans[i] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
AtCoder/ABC253/F/data/example_00.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_00.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/example_00.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_00.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/example_01.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/example_01.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_01.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/example_02.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/example_02.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/example_02.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_00.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_00.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_00.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_00.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_01.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_01.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_01.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_02.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_02.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_02.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_03.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_03.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_03.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_03.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_04.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_04.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_04.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_04.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_05.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_05.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_05.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_05.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_06.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_06.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_06.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_06.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_07.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_07.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_07.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_07.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_08.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_08.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_08.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_08.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_09.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_09.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_09.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_09.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_10.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_10.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_11.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_11.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_12.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_12.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_13.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_13.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_14.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_14.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_15.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_15.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_16.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_16.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_17.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_17.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_18.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_18.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_19.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_19.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_20.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_20.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_21.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_21.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_21.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_21.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_22.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_22.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_22.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_22.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_23.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_23.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_23.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_23.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_24.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_24.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_24.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_24.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_25.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_25.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_25.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_25.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_26.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_26.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_26.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_26.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_27.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_27.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_27.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_27.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_28.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_28.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_28.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_28.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_29.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_29.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_29.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_29.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_30.in
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_30.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AtCoder/ABC253/F/data/test_30.out
(Stored with Git LFS)
Normal file
BIN
AtCoder/ABC253/F/data/test_30.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user