• 【luogu P4113 [HEOI2012]采花】 假题解


    题目链接:https://www.luogu.org/problemnew/show/P4113
    为什么要卡莫队!为什么加强的这么毒瘤!
    莫队可以拿100分剩下三个点没治了

    // luogu-judger-enable-o2
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define ri register
    #define il inline
    using namespace std;
    const int maxn = 1000001;
    inline int read()
    {
        int k=0;
        char c;
        c=getchar();
        while(!isdigit(c))c=getchar();
        while(isdigit(c)){k=(k<<3)+(k<<1)+c-'0';c=getchar();}
        return k;
    }
    int n, m, c, answer, bl, curL = 1, curR = 0;
    int a[maxn], cnt[maxn], ans[maxn];
    struct Query{
        int l, r, p;
        friend bool operator < (const Query &a, const Query &b)
        {
            return (a.l/bl) == (b.l/bl) ? a.r < b.r : a.l < b.l;
        }
    }q[maxn];
    il void add(int pos)
    {
        ++cnt[a[pos]];
        if(cnt[a[pos]] == 2) answer++;
    }
    il void del(int pos)
    {
        --cnt[a[pos]];
        if(cnt[a[pos]] == 1) answer--;
    }
    int main()
    {
        n = read(); c = read(); m = read();
        bl = sqrt(n);
        for(ri int i = 1; i <= n; i++)
        a[i] = read();
        
        for(ri int i = 1; i <= m; i++)
        {
            int l,r;
            l = read(); r = read();
            q[i].l = l;
            q[i].r = r;
            q[i].p = i;
        }
        sort(q+1,q+1+m);
        for(ri int i = 1; i <= m; i++)
        {
            int L = q[i].l, R = q[i].r;
            while(curL < L) del(curL++);
            while(curL > L) add(--curL);
            while(curR < R) add(++curR);
            while(curR > R) del(curR--);
            ans[q[i].p] = answer;
        }
        for(int i = 1; i <= m; i++)
        printf("%d
    ",ans[i]);
        return 0;
    }
    

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    [NOI2012] 美食节
    [NOI2008] 志愿者招募
    P3834 【模板】可持久化线段树 2(主席树)
    P3919 【模板】可持久化线段树 1(可持久化数组)
    P4168 [Violet]蒲公英
    轻重链剖分
    沉舟侧畔千帆过 病树前头万木春
    P2119 魔法阵 (0.1s 虐杀过程)
    两行虐杀儒略历
    CSP2020 S-2 爆零(日)记 (已完结)
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9214130.html
Copyright © 2020-2023  润新知