Submit Info #2660

Problem Lang User Status Time Memory
Point Add Range Sum cpp null0124 WA 423 ms 7.30 MiB

ケース詳細
Name Status Time Memory
example_00 WA 6 ms 0.62 MiB
max_random_00 WA 421 ms 7.25 MiB
max_random_01 WA 409 ms 7.30 MiB
max_random_02 WA 423 ms 7.25 MiB
max_random_03 WA 412 ms 7.25 MiB
max_random_04 WA 421 ms 7.25 MiB
random_00 WA 336 ms 6.88 MiB
random_01 WA 345 ms 6.84 MiB
random_02 WA 228 ms 3.13 MiB
random_03 WA 67 ms 4.75 MiB
random_04 WA 105 ms 5.13 MiB

/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <stdio.h> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> /*多倍長整数/cpp_intで宣言 #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; */ #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define rep(i, n) for(int i = 0; i < (n); ++i) #define rep1(i, n) for(int i = 1; i <= (n); ++i) #define rep2(i, n) for(int i = 2; i < (n); ++i) #define repr(i, n) for(int i = n; i >= 0; --i) #define reprm(i, n) for(int i = n - 1; i >= 0; --i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printin(a) printf(a ? "possible\n" : "inposible\n") #define printdb(a) printf("%.50lf\n", a)//少数出力 #define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ) #define prints(s) printf("%s\n", s.c_str())//string出力 #define all(x) (x).begin(), (x).end() #define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数 #define pb push_back #define priq priority_queue #define rpriq priq<int, vector<int>, greater<int>> #define deg_to_rad(deg) (((deg)/360.0)*2.0*PI) #define rad_to_deg(rad) (((rad)/2.0/PI)*360.0) #define Please return #define AC 0 #define debug(aa, a) fprintf(stderr, aa, a) using ll =long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1000000007; const long double PI = acos(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c);//最初の改行対策 while (c != '\n' && c != -1) { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll number1, ll number2) {//lcmを求める return number1 / gcd(number1, number2) * number2; } /*-----------------------------------------ここからコード-----------------------------------------*/ template<typename T> struct segtree { vector<T> seg; ll siz;//木の1/2の大きさ T unit; //const function<T(T, T)> f; segtree(ll n, const T a) {//n の大きさ, a (単位元) で segtree を初期化する siz = 1; while (siz < n)siz <<= 1; seg.assign(2 * siz - 1, a); unit = a; } void set(ll k, const T &t) {//k (0-indexed) 番目に t を代入 seg[k + siz - 1] = t; } void build(const function<T(T, T)> f) {//f によって木を構築 for (ll i = siz - 2; i >= 0; --i) seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]); } void update(ll k, T a, const function<T(T, T)> f) {//k の値を a に更新,更新に使う二項演算 k += siz - 1; seg[k] = a; while (k > 0) { k = ((k - 1) >> 1); seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]); } } private: T queryr(const ll a, const ll b, ll k, ll l, ll r, const function<T(T, T)> f) {//再帰用関数 if (r <= a || b <= l)return unit;//全く関係ないので単位元を返す else if (a <= l && r <= b)return seg[k];//全部おおわれているのでその seg を返す else { T vall = queryr(a, b, k * 2 + 1, l, ((r + l) >> 1), f); T valr = queryr(a, b, k * 2 + 2, ((r + l) >> 1), r, f); return f(vall, valr); } } public: T query(ll a, ll b, const function<T(T, T)> f) {//[a, b) について f した結果を返す return queryr(a, b, 0L, 0L, siz, f); } }; int main() { int n, q; scanf("%d%d", &n, &q); int a; segtree<int> tree(n, 0); rep(i, n) { scanf("%d", &a); tree.set(i, a); } tree.build([](int a, int b) {return (a + b); }); int t, l, r; rep(i, q) { scanf("%d%d%d", &t, &l, &r); if (t)printf("%d\n", tree.query(l, r, [](int a, int b) {return (a + b); })); else tree.update(l, r, [](int a, int b) {return (a + b); }); } Please AC; }