Bzoj 3236: [Ahoi2013] job | MO Team Algorithm | tree-like array

Source: Internet
Author: User

The problem is clearly a two-dimensional approach
to use the team offline to the query after the maintenance of two tree array, record the answer of two queries, for the second query, you can open an array, record the number of occurrences of each count

#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <set> #include <map> #include <iostream> #include <algorithm> #
Define Lowbit (x) (x&) #define N 100010 using namespace std;
    int SC () {int i=0,f=1; char C=getchar (); while (c> ' 9 ' | |
    c< ' 0 ') {if (c== '-') F=-1;c=getchar ();}
    while (c>= ' 0 ' &&c<= ' 9 ') i=i*10+c-' 0 ', C=getchar ();
return i*f; } struct W{int l,r,a,b,p;}
A[N*10];
int sum[n],tr[n],tr[n],v[n];
int bl[n],ans[n*10][2];
int n,m,block; BOOL CMP (W x,w y) {return bl[x.l]==bl[y.l]?x.r<y.r:bl[x.l]<bl[y.l];} void change (int x,int f,int *tr) {fo
R (; x<=n;x+=lowbit (x)) tr[x]+=f;
    } int Ask (int x,int *tr) {if (x<1) return 0;
    int ans=0;
    for (; x;x-=lowbit (x)) ans+=tr[x];
return ans;
    } void Add (int x) {change (X,1,TR);
    sum[x]++;
if (sum[x]==1) change (X,1,TR);
    } void del (int x) {change (X,-1,TR); SUM[X]--;
if (sum[x]==0) change (X,-1,TR);
    } int main () {N=SC (), M=SC (); block=sqrt (n);
        for (int i=1;i<=n;i++) {V[I]=SC ();
    bl[i]= (i-1)/block+1;
    } for (int i=1;i<=m;i++) A[I].L=SC (), A[I].R=SC (), A[I].A=SC (), A[I].B=SC (), a[i].p=i;
    Sort (a+1,a+m+1,cmp);
    int l=a[1].l,r=a[1].l-1;
        for (int. i=1;i<=m;i++) {while (L&LT;A[I].L) del (v[l++]);
        while (L&GT;A[I].L) add (V[--l]);
        while (R&GT;A[I].R) del (v[r--]);
        while (R&LT;A[I].R) add (V[++r]);
        Ans[a[i].p][0]=ask (A[I].B,TR)-ask (A[I].A-1,TR);
    Ans[a[i].p][1]=ask (A[I].B,TR)-ask (A[I].A-1,TR);
    } for (int i=1;i<=m;i++) printf ("%d%d\n", ans[i][0],ans[i][1]);
return 0; }

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.