New Ket Practice 7 E-Cosette's series (tree-shaped array + explode long long solution)

Source: Internet
Author: User
Tags explode

Https://www.nowcoder.com/acm/contest/38/E

Test instructions

Ideas:

Tree-like array maintenance. Learn from the big guy how to deal with the explosion of long long method.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 Const intMAXN =1000000+ -;8 9 intN;Ten intA[MAXN],B[MAXN]; One ll C[MAXN]; A  - intLowbit (intx) - { the     returnx& (-x); - } -  - voidAddintXintd) + { -      while(x<MAXN) +     { AC[X] + =D; atX + =lowbit (x); -     } - } -  -ll sum (intx) - { inLL ret =0; -      while(x>0) to     { +RET + =C[x]; -X-=lowbit (x); the     } *     returnret; $ }Panax Notoginseng  - intMain () the { +     //freopen ("In.txt", "R", stdin); Ascanf"%d",&n); the      for(intI=1; i<=n;i++) +     { -scanf"%d",&a[i]); $B[i] =A[i]; $     } -Sort (b +1, b+n+1); -     intnum = unique (b +1, b+n+1)-(b +1); thell ans1 =0, Ans2 =0; -ll mx =1e18;Wuyi      for(intI=1; i<=n;i++) the     { -A[i] = Lower_bound (b +1, b+n+1, A[i])-(b +1); Wua[i]++; -Ans1 + = (ll) (n-i+1) * (SUM (n)-sum (a[i])); About         if(ans1>=mx) Ans2 + = Ans1/mx, ans1%=MX; $ Add (a[i],i); -     } -     if(ANS2) printf ("%lld%018lld\n", ans2,ans1); -     Elseprintf"%lld\n", ans1); A     return 0; +}

New Ket Practice 7 E-Cosette's series (tree-shaped array + explode long long solution)

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.