CF Gym 100463A tree-like array for reverse order number

Source: Internet
Author: User

Test instructions: give you a sequence, and a standard sequence line, to find the intersection of points.

The best way to do this is to find the number of reverse order, and use array array to optimize it.

Do eight digital time, ask for reverse number search how to beg, but the practice forgot ... So on the spot how to achieve, the results of 1 hours to get out, but also wa a longlong, the foundation is not solid

#include <cstdio>#include<cmath>#include<vector>#include<map>#include<Set>#include<algorithm>#include<cstring>using namespacestd;//#define LOCALtypedefLong Longll;Const intMAXN =1000000+ -;#defineLowbit (x) ((x) &-(x))ll C[maxn];ll n,a,b;voidAdd (ll x,ll d) { while(x <=N) {c[x]+=d; x+=lowbit (x); }}ll sum (ll x) {LL ret=0;  while(X >0) {ret+ = C[x]; x-=lowbit (x); }    returnret;} ll Count () {ll res=0; ll Ele=b;  for(inti =0; I < n; i++) {ll pre= SUM (ele+1); Res+ = Ele-Pre; Add (Ele+1,1); Ele= (ele+a)%N; }    returnRes;}intMain () {#ifdef local freopen ("In.txt","R", stdin); //freopen ("OUT.txt", "w", stdout);#endif //Local    intCAS =0;  while(~SCANF ("%i64d%i64d%i64d", &n,&a,&b) &&N) {memset (C,0,sizeof(C)); printf ("Case %d:%i64d\n",++Cas,count ()); }    return 0;}

CF Gym 100463A tree array for inverse number

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.