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)