Codeforces 61e enemy is weak evaluate the logarithm tree array of I <j <K & A [I]> A [J]> A [k]

Source: Internet
Author: User

Question link: Click the open link

Evaluate the logarithm of I <j <K & A [I]> A [J]> A [k]

If there are only 2 tuples, the reverse order is used.

A tree array X is used to represent the number before the number I.

Then, sum the array y, and store the number of> A [I] in array X to array y.


# Include <algorithm> # include <cctype> # include <cassert> # include <cstdio> # include <cstring> # include <climits> # include <vector> # include <iostream> using namespace STD; # define ll long longinline void RD (Int & RET) {char C; do {c = getchar ();} while (C <'0' | C> '9'); ret = C-'0'; while (C = getchar ()> = '0' & C <= '9') ret = RET * 10 + (c-'0 ');} # define n 1000005 # define EPS 1e-8 # define INF limit 00ll N; struct node {ll C [N]; inline ll lowbit (ll x) {return X &-X ;} void Init () {memset (C, 0, sizeof C);} ll sum (ll x) {ll ans = 0; while (x <= N + 10) ans + = C [X], x + = lowbit (x); Return ans;} void change (ll x, ll y) {While (X) c [x] + = Y, X-= lowbit (x) ;}} X, Y; int haifei [1000000], panting [1000000]; int main () {ll I, j; while (CIN> N) {ll ans = 0; for (I = 0; I <n; I ++) rd (haifei [I]), panting [I] = haifei [I]; X. init (); Y. init (); sort (haifei, haifei + n); for (I = 0; I <n; I ++) {LL B = (lower_bound (haifei, haifei + N, panting [I])-haifei) + 1; ll siz = y. sum (B); ans + = siz; Y. change (B, X. sum (B); X. change (B, 1) ;}cout <ans <Endl;} 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.