From f92ffbba4f419a13c5de95114c21e6b6b44ef814 Mon Sep 17 00:00:00 2001 From: orzcyand1317 <36555123+orzcyand1317@users.noreply.github.com> Date: Sun, 3 Mar 2019 07:37:39 +0800 Subject: [PATCH] Update segment.md --- docs/ds/segment.md | 53 +++++++++++++++-------------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/docs/ds/segment.md b/docs/ds/segment.md index 80de83c3..79372b18 100644 --- a/docs/ds/segment.md +++ b/docs/ds/segment.md @@ -266,7 +266,6 @@ int getsum(int l, int r, int s, int t, int p) { ```cpp #include -using namespace std; typedef long long LL; LL n, a[100005], d[270000], b[270000]; void build(LL l, LL r, LL p) { @@ -305,32 +304,17 @@ LL getsum(LL l, LL r, LL s, LL t, LL p) { return sum; } int main() { - ios::sync_with_stdio(0); + std::ios::sync_with_stdio(0); LL q, i1, i2, i3, i4; - cin >> n >> q; - for (LL i = 1; i <= n; i++) cin >> a[i]; + std::cin >> n >> q; + for (LL i = 1; i <= n; i++) std::cin >> a[i]; build(1, n, 1); while (q--) { - cin >> i1 >> i2 >> i3; + std::cin >> i1 >> i2 >> i3; if (i1 == 2) - cout << getsum(i2, i3, 1, n, 1) << endl; + std::cout << getsum(i2, i3, 1, n, 1) << endl; else - cin >> i4, update(i2, i3, i4, 1, n, 1); - } - return 0; -} -int main() { - ios::sync_with_stdio(0); - LL q, i1, i2, i3, i4; - cin >> n >> q; - for (LL i = 1; i <= n; i++) cin >> a[i]; - build(1, n, 1); - while (q--) { - cin >> i1 >> i2 >> i3; - if (i1 == 2) - cout << getsum(i2, i3, 1, n, 1) << endl; - else - cin >> i4, update(i2, i3, i4, 1, n, 1); + std::cin >> i4, update(i2, i3, i4, 1, n, 1); } return 0; } @@ -343,15 +327,8 @@ int main() { 代码: ```cpp -#include -#include -#include #include -#include -#include -#include -#include -using namespace std; + #define ll long long ll read() { ll w = 1, q = 0; @@ -491,7 +468,7 @@ int main() { ```cpp #include -using namespace std; + int n, a[100005], d[270000], b[270000]; void build(int l, int r, int p) { if (l == r) { @@ -531,18 +508,18 @@ int getsum(int l, int r, int s, int t, int p) { return sum; } int main() { - ios::sync_with_stdio(0); - cin >> n; - for (int i = 1; i <= n; i++) cin >> a[i]; + std::ios::sync_with_stdio(0); + std::cin >> n; + for (int i = 1; i <= n; i++) std::cin >> a[i]; build(1, n, 1); int q, i1, i2, i3, i4; - cin >> q; + std::cin >> q; while (q--) { - cin >> i1 >> i2 >> i3; + std::cin >> i1 >> i2 >> i3; if (i1 == 0) - cout << getsum(i2, i3, 1, n, 1) << endl; + std::cout << getsum(i2, i3, 1, n, 1) << endl; else - cin >> i4, update(i2, i3, i4, 1, n, 1); + std::cin >> i4, update(i2, i3, i4, 1, n, 1); } return 0; } -- 2.11.0