POJ2299 Ultra-quicksort

Source: Internet
Author: User

Transmission Door

The tree-like array for reverse order + discretization?

I never seem to remember how to use a tree-like array to reverse the order. Before I remember all is writing, this time how to write to be able to go backwards ...

Then the scope of the subject A is very large, but the range of n is not small, 500000, need to be a discrete wave, then can be normal according to the tree array operation. And then, in query, pay attention to-1.

Let's take a look at the code.

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<queue>#include<cstring>#include<utility>#include<map>#definePR pair<int,int>#defineMP Make_pair#defineFi first#defineSC Second#defineRep (i,a,n) for (int i = a;i <= n;i++)#definePer (i,n,a) for (int i = n;i >= a;i--)#defineEnter Putchar (' \ n ')#defineLowbit (x) x & (-X)using namespaceStd;typedefLong Longll;Const intM =500005;Const intN =32005;intRead () {intAns =0, op =1; CharCH =GetChar ();  while(Ch <'0'|| CH >'9')    {    if(ch = ='-') op =-1; CH=GetChar (); }     while(Ch >='0'&& CH <='9') {ans*=Ten; Ans+ = CH-'0'; CH=GetChar (); }    returnAns *op;}intn,a[m],c[m],tot,d[m];ll ans;voidAddintx) {     while(x <= m5) A[x]++,x + =lowbit (x);}intQueryintx) {    intCur =0;  while(x) cur + = a[x],x-=lowbit (x); returncur;}voidClear () {tot= ans =0; Memset (A,0,sizeof(a));}intMain () { while(1) {n=read (); if(n = =0) Break;    Clear (); Rep (I,1, n) c[i] = Read (), d[i] =C[i]; Sort (c+1, c+1+N); Tot= Unique (c+1, c+1+N)-C-1; Per (I,n,1)    {        intK = Lower_bound (c+1, c+1+tot,d[i])-C; //printf ("#%d\n", k);Ans + = query (K-1), add (k); } printf ("%lld\n", ans); }    return 0;}

POJ2299 Ultra-quicksort

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.