• 【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;
    }
    

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

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

  • 相关阅读:
    POJ 3009 Curling 2.0 简单DFS 好题
    POJ 3253 Fence Repair 贪心
    python_13 面向对象
    python_12 模块
    python练习题_04
    python_11 装饰器,闭包
    python练习题_03
    python_10 迭代器和生成器
    python_09 文件处理流程,文件操作方法
    python_08 函数式编程、高阶函数、map、filter、reduce函数、内置函数
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9214130.html
Copyright © 2020-2023  润新知