4542: [Hnoi2016] Large number | MO Team

Source: Internet
Author: User

HN one day Test two Mo team is what ghost. Or the team is not the right posture.
Think about that already. L. . R New additions to the answers R+1 How to update the current answer
The suffix needs to be preprocessed first modp The value < Span class= "Mrow" id= "mathjax-span-4232" > b i Span style= "Display:inline-block; width:0px; Height:2.102em; " > , assume that the sub-sequence L. . R Mode p The value is x
So x?10 r l +b[R]=b[L] And then you can just count the team.
When the modulus is 2 or 5, a special sentence is needed.

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <vector>#include <cmath>#include <queue>#include <ctime>#include <set>#include <map>#define N 110000#define LL Long LongUsing namespace Std;struct w{intL,r,p;}Q[n]; chars[N];long long Sum[n],mod,ss[n],ans[n];long long a[n],b[n],c[n],h[n],now;intBl[n],cnt[n];intNm, Q,tot,block;void Solve_2_5 () { for(intI=1; i<=n;i++) {ss[i]=ss[i-1]; sum[i]=sum[i-1];if((s[i]-' 0 ')%mod==0) sum[i]+=i,ss[i]++; } scanf ("%d", &q); for(intI=1; i<=q;i++) {intL,R;SCANF ("%d%d", &l,&r);printf("%lld\ n", sum[r]-sum[l-1]-(ss[r]-ss[l-1])*(L-1)); }}bool CMP (int x,int y){returnb[x]<b[y];} BOOL Cmp1 (W a,w b) {returnbl[a.l]<bl[b.l]| | (BL[A.L]==BL[B.L]&AMP;&AMP;A.R&LT;B.R);}intMain () {scanf ("%lld%s", &mod,s+1); N=strlen (s+1); block=sqrt(n);if(mod==2|| mod==5) {solve_2_5 ();return 0; } a[0]=1; for(intI=1; i<=n;i++) a[i]=Ten*a[I1]%mod; for(inti=n;i>=1; i--) b[i]= (A[n-i]*(s[i]-' 0 ') +b[i+1])%mod; for(intI=1; i<=n;i++) c[i]=i;Sort(c+1, c+n+1, CMP); for(intI=1; i<=n;i++)if(b[c[i]]==b[c[i-1]]) H[c[i]]=tot;ElseH[c[i]]=++tot; for(intI=1; i<=n;i++) bl[i]= (i-1)/block; scanf"%d", &q); for(intI=1; i<=q;i++) scanf ("%d%d",&Q[i].l,&Q[i]. R),Q[i]. p=i;Sort(Q+1,Q+q+1, CMP1);intL=1, r=0; for(intI=1; i<=q;i++) { while(l>Q[i]. L) now+=cnt[h[l-1]]+ (h[r+1]==h[l-1]), cnt[h[--l]]++; while(r<Q[i]. R) cnt[h[++r]]++,now+=cnt[h[r+1]]; while(l<Q[i]. L) Cnt[h[l]]--, now-=cnt[h[l]]+ (h[r+1]==h[l]), l++; while(r>Q[i]. R) now-=cnt[h[r+1]],cnt[h[r--]]--; ans[Q[i]. P]=now; } for(intI=1; i<=q;i++)printf("%lld\ n", Ans[i]);return 0;}

4542: [Hnoi2016] Large number | MO Team

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.