Another Version of inversion two-dimensional tree array for inverse order

Source: Internet
Author: User

Another Version of inversion

Test instructions: There are only 2 ways to walk, to the right or down, to first go to a large number, in a small number of this way there are how many. In other words, we find out the inverse number of this 2-dimensional matrix.

Solving the puzzle: two-dimensional array + reverse order the number is finished.

Code:

1#include <bits/stdc++.h>2 using namespacestd;3 #defineFopen freopen ("_in.txt", "R", stdin); Freopen ("_out.txt", "w", stdout);4 #defineLL Long Long5 #defineULL unsigned LL6 #defineFi first7 #defineSe Second8 #definePB Push_back9 #defineLson l,m,rt<<1Ten #defineRson m+1,r,rt<<1|1 One #defineMax3 (A,B,C) max (A,max (b,c)) A #defineMin3 (a,b,c) min (a,min (b,c)) -typedef pair<int,int>PLL; - Const intINF =0x3f3f3f3f; the ConstLL mod = 1e9+7; - Const intN = 1e5+Ten; - structnode{ -     intA, id; +     intx, y; -}a[305*305]; + BOOLCMP (node x1, node x2) { A     if(x1.a = = x2.a)returnX1.id >x2.id; at     returnx1.a >x2.a; - } - intLowbit (intx) { -     returnx& (-x); - } - intN, M; inLL tree[305][305]; - voidUpdateintXinty) { to      for(inti = x; I <= N; i+=lowbit (i)) +          for(intj = y; J <= M; J + =Lowbit (j)) -tree[i][j]++; the } *LL Query (intXinty) { $LL ret =0;Panax Notoginseng      for(inti = x; I i-=lowbit (i)) -          for(intj = y; J j-=Lowbit (j)) theRET + =Tree[i][j]; +     returnret; A } the intMain () { +     ///Fopen; -scanf"%d%d", &n, &m); $     intt =0; $      for(inti =1; I <= N; i++) -          for(intj =1; J <= M; J + +){ -t++; thescanf"%d", &a[t].a); -a[t].x =i;WuyiA[T].Y =J; theA[t].id =T; -           //cout << ' s ' <<a[i].id << Endl; Wu         } -Sort (A +1, A +1+T, CMP); AboutLL ans =0; $      for(inti =1; I <= t; i++){ -         //cout << a[i].id << ' << a[i].x << ' << a[i].y << Endl; -Ans + =query (A[I].X,A[I].Y); - Update (a[i].x, A[I].Y); A     } +printf"%i64d", ans); the     return 0; -}
another Version of inversion

Another Version of inversion two-dimensional tree array for inverse order

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.