Bzoj 3289 Mato File Management | Mo Team Tree-like array

Source: Internet
Author: User

Bzoj 3289 Mato's file management test instructions

To find the inverse of the interval.

Exercises

On the basis of the team, we use the tree-like array to find the inverse.

When a number is added to the left of the current interval, the number of the original range of Res + + is smaller than that of it;
When a number is added to the right of the current interval, the number of the Res + + original interval is larger than its size;
When a number is deleted to the left of the current interval, the number of the res-= original interval is smaller than it.
When a number is deleted to the right of the current interval, the number of the res-= original interval is greater than it;

#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespaceStdtypedef Long LongllTemplate<classT>voidRead (T &x) {CharCBOOLOP =0; while(c = GetChar (), C <' 0 '|| C >' 9 ')if(c = ='-') op =1; x = C-' 0 '; while(c = GetChar (), C >=' 0 '&& C <=' 9 ') x = x *Ten+ C-' 0 ';if(OP) x =-X.;}Template<classT>voidWrite (T x) {if(X <0) Putchar ('-'), x =-X;if(x >=Ten) Write (X/Ten); Putchar (' 0 '+ x%Ten);}#define Space Putchar (")#define ENTER Putchar ('\n ')Const intN =50005, B =233;intN, M, A[n], lst[n], IDX,TR[N], pl =1, Pr;ll Res, ans[n];#define BEL (x) (((x)-1)/B + 1)structQuery {intID, L, R;BOOL operator< (ConstQuery &b)Const{returnBel (l) = = Bel (B.L)?    R < B.r:l < B.L; }} Q[n];voidAddintPintx) { while(P <= idx)TR[P] + = x, p + = P & p;}intAskintP) {intres =0; while(p) Res + =TR[P], P-= p & p;returnRes;}intMain () {read (n); for(inti =1; I <= N;    i++) read (A[i]), lst[i] = a[i]; Sort (LST +1, LST + n +1); IDX = unique (LST +1, LST + n +1)-LST-1; for(inti =1; I <= N; i++) A[i] = Lower_bound (LST +1, LST + idx +1, A[i])-lst; Read (m); for(inti =1; I <= m;    i++) Q[i].id = i, read (Q[I].L), read (Q[I].R); Sort (q +1, q + M +1); for(inti =1; I <= m; i++) { while(PL > Q[i].l) res + = Ask (A[--pl]-1), add (A[PL],1); while(PR < Q[I].R) Res + = Ask (idx)-ask (A[++PR]), add (A[PR],1); while(PL < Q[I].L) Add (A[PL],-1), Res-= Ask (a[pl++]-1); while(pr > Q[I].R) Add (A[PR],-1), Res-= Ask (IDX)-ask (a[pr--]);    Ans[q[i].id] = res; } for(inti =1; I <= m; i++) write (Ans[i]), enter;return 0;}

Bzoj 3289 Mato File Management | Mo Team Tree-like array

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.