ACM-ICPC LA 4329 Ping pong (tree-like array)

Source: Internet
Author: User

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=2330

Reference: "An introduction to Algorithms Classic Training Guide" Rujia P197

The book above is written on the main topic, the problem-solving ideas are written out.

I put my own in here.

AC Code:

1#include <stdio.h>2#include <string.h>3 4 #definePeople 200015 #defineVALUE 1000016 7typedefLong LongLL;8 9 intN, A[people], amin[people], amax[people], tree[value];Ten  One  A intLowbit (intx) { -     returnX &-x; - } the  - voidAddintXintd) { -      while(X <VALUE) { -TREE[X] + =D; +X + =lowbit (x); -     } + } A  at intSumintx) { -     intRET =0; -      while(X >0){ -RET + =Tree[x]; -X-=lowbit (x); -     } in     returnret; - } to  + intMain () { -     intT; thescanf"%d", &t); *      while(t--){ $scanf"%d", &n);Panax Notoginseng          for(inti =1; I <= N; ++i) { -scanf"%d", &a[i]); the         } +  Amemset (Tree,0,sizeof(tree)); the          for(inti =1; I <= N; ++i) { +Amin[i] = SUM (a[i]-1);//I personal statistics on the left of the first person and the total number of skill values less than -Amax[i] = i-1-Amin[i];//statistics skill value is greater than first person and total number of people on the left $Add (A[i],1); $         } -  -LL ans =0; thememset (Tree,0,sizeof(tree)); -          for(inti = n; I >=1; --i) {WuyiLL bmin = SUM (a[i]-1);//The total number of statistics skill values less than the first person and on the right of the first person theAns + = Bmin * Amax[i] + (N-i-bmin) *Amin[i]; -Add (A[i],1); Wu         } -printf"%lld\n", ans); About     } $     return 0; -}

ACM-ICPC LA 4329 Ping pong (tree-like array)

Related Article

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.