Bzoj 5055: Film Mage tree array + discrete

Source: Internet
Author: User

First enumerate each number, see it before there are several smaller than it, calculate and for sum1, behind a few bigger than it, calculate and for sum2, the contribution of the answer for A[I]*SUM1*SUM2.

After discretization, the tree array is available.

is upside down, along one side, statistics OK, discrete is for size, order (easy to go heavy)

1#include <cstdio>2#include <algorithm>3#include <cmath>4#include <iostream>5#include <cstring>6#include <map>7 #defineMoD 192608178 #defineN 3000079 #definell Long LongTen using namespacestd; One  A intN,top; - ll ans; - ll A[n],tree[n],c[n]; themap<int,int>p; - structNode - { -     intZhi,id; + }b[n]; -  + BOOLcmp (Node x,node y) A { at     returnx.zhi<Y.zhi; - } - intLowbit (intx) {returnx& (-x);} -ll query (intx) - { -ll res=0; in      for(inti=x;i>=1; i-=lowbit (i)) -res+=Tree[i]; tores%=MoD; +     returnRes;  - } the voidAddintx,ll z) * { $      for(inti=x;i<=top;i+=lowbit (i))Panax Notoginsengtree[i]= (tree[i]+z)%MoD; - } the intMain () + { A p.clear (); thescanf"%d",&n); +      for(intI=1; i<=n;i++) -     { $scanf"%d",&a[i]); $a[i]%=MoD; -B[i].zhi=A[i]; -B[i].id=i; the     } -Sort (b +1, b+n+1, CMP);Wuyib[0].zhi=- +; the      for(intI=1; i<=n;i++) -         if(b[i].zhi!=b[i-1].zhi) p[b[i].zhi]=++top; Wu      for(intI=1; i<=n;i++) -     { AboutC[i]=1ll*query (p[a[i]]-1) *a[i]%MoD; $ Add (P[a[i]],a[i]); -     } -memset (Tree,0,sizeof(tree)); -      for(inti=n;i>=1; i--) A     { +ans= (ans+1ll*c[i]* (query (top)-query (P[a[i]) +mod))%MoD; the Add (P[a[i]],a[i]); -     } $printf"%lld", ans); the}

Bzoj 5055: Film Mage tree array + discrete

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.