From c0fb0094dc189df7d83c1b23110104ff4a909d03 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 3 Jan 2021 08:16:25 +0800 Subject: [PATCH] =?UTF-8?q?#10115.=20=E3=80=8C=E4=B8=80=E6=9C=AC=E9=80=9A?= =?UTF-8?q?=204.1=20=E4=BE=8B=203=E3=80=8D=E6=A0=A1=E9=97=A8=E5=A4=96?= =?UTF-8?q?=E7=9A=84=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1025566 --- LibreOJ/10115/10115.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LibreOJ/10115/10115.cpp diff --git a/LibreOJ/10115/10115.cpp b/LibreOJ/10115/10115.cpp new file mode 100644 index 00000000..94055c1a --- /dev/null +++ b/LibreOJ/10115/10115.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; + +int n, m, op, l, r, c1[1000001], c2[1000001]; + +int lowbit(int x) { + return x & (-x); +} + +inline void update1(int x, int v) { + while (x <= n) { + c1[x] += v; + x += lowbit(x); + } +} + +inline void update2(int x, int v) { + while (x <= n) { + c2[x] += v; + x += lowbit(x); + } +} + +int sum1(int x) { + int p = 0; + while (x > 0) { + p += c1[x]; + x -= lowbit(x); + } + return p; +} + +int sum2(int x) { + int p = 0; + while (x > 0) { + p += c2[x]; + x -= lowbit(x); + } + return p; +} + +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> op >> l >> r; + if (op == 1) { + update1(l, 1), update2(r, 1); + } + if (op == 2) { + cout << sum1(r) - sum2(l - 1) << endl; + } + } + return 0; +} \ No newline at end of file