Codeforces round #141 (Div. 2), problem: (d) zigzag line segment tree integer variable pay attention to overflow control

Source: Internet
Author: User

Practice: At the beginning, I did not pay attention to integer data for LL processing ..

# Include <cstdio> # include <cstring> # define left L, M, x <1 # define right m + 1, R, x <1 | 1 typedef long ll; const int LMT = 100003; // bad programming habits. Ll sum [5] [12] [LMT <2]; int Z; ll query (int l, int R, int L, int R, int X) {If (L <= L & R <= r) return sum [Z-2] [(L-L + 1) % (z <1)-2)] [X]; int M = (L + r)> 1; ll res = 0; If (L <= m) RES + = query (L, R, left ); if (r> m) RES + = query (L, R, right); Return res;} void Update (INT op, int POs, int L, int R, int X) {If (L = r) {int I, j; for (I = 2; I <= 6; ++ I) for (j = 0; j <(I <1)-2; ++ J) if (j> I) sum [I-2] [J] [x] = op * (LL (I) <1)-j ); // here, else if (j> 0 & J <= I) Su M [I-2] [J] [x] = LL (1) * op * j; else sum [I-2] [J] [x] = LL (OP) <1; return;} int M = (L + r)> 1, I, j, Le = m-L + 1; if (Pos <= m) update (OP, POs, left); else Update (OP, POs, right); for (I = 2; I <= 6; ++ I) for (j = 0; j <(I <1)-2; ++ J) sum [I-2] [J] [x] = sum [I-2] [J] [x <1] + sum [I-2] [(j + le) % (I <1)-2)] [x <1 | 1];} int main (void) {// two % d are written at the beginning... Int L, R, I, n, T, V, X; scanf ("% d", & N); for (I = 1; I <= N; ++ I) {scanf ("% d", & X); Update (X, I, 1, n, 1);} scanf ("% d ", & T); While (t --) {scanf ("% d", & X); if (1 = x) {scanf ("% d ", & L, & V); Update (v, L, 1, n, 1);} else {scanf ("% d", & L, & R, & Z); printf ("% i64d \ n", query (L, R, 1, n, 1) ;}} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.