1 条题解

  • 0
    @ 2025-10-8 16:58:38
    #include <bits/stdc++.h> 
    using namespace std;
    const int N=5e5+10;
    int n, m, c1[N], c2[N];
    void add(int c[], int x, int k){for(;x<=n;x+=x&-x)c[x]=c[x]+k;}
    int sum(int c[], int x){int res=0;for(;x>=1;x-=x&-x)res=res+c[x];return res;}
    int main()
    {
        scanf("%d%d", &n, &m);
        memset(c1, 0, sizeof(c1));memset(c2, 0, sizeof(c2));
        for(int i=1, op, x, y;i<=m;i++)
        {
            scanf("%d%d%d", &op, &x, &y);if(x>y)swap(x, y);
            if(op==1)add(c1, x, 1), add(c2, y+1, 1); 
            else printf("%d\n", sum(c1, y)-sum(c2, x));
        }
        return 0;
    }
    
    • 1

    *【线段树|双树状数组】一维区间修改+区间极值查询(好题)

    信息

    ID
    1803
    时间
    1000ms
    内存
    512MiB
    难度
    8
    标签
    (无)
    递交数
    266
    已通过
    50
    上传者