社区讨论

谁能解释一下最优解

P4939Agent2参与者 4已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@m5v6zty1
此快照首次捕获于
2025/01/13 23:22
去年
此快照最后确认于
2025/11/04 11:39
4 个月前
查看原帖
CPP
#include <cstdio>
#include <cctype>

__always_inline static void read(int &x){
    
    char c = getchar_unlocked();
    
    x = 0;
    while (!isdigit(c)) c = getchar_unlocked();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar_unlocked();
    
}

inline static void write(const int &x){
    
    if (x > 9) write(x / 10);
    putchar_unlocked(x % 10 + '0');
    
}

__always_inline static void writeln(const int &x){write(x),putchar_unlocked('\n');}

const int N  = 1e7 + 5;

int n,m,tree[N];

__always_inline static int lowbit(int x){return x & (-x);}

void update(int x,int y){

    for (;x <= n;x += lowbit(x)) tree[x] += y;

}

int query(int x){

    int ans = 0;

    for (;x;x -= lowbit(x)) ans += tree[x];

    return ans;
}

int main(){

    #ifndef ONLINE_JUDGE
        freopen("P4939.in","r",stdin);
    #endif

    for (read(n),read(m);m--;){

        int op,a,b;

        read(op),read(a);
        switch (op){

            case 0:read(b);update(a,1);update(b + 1,-1);break;
            case 1:writeln(query(a));break;

        }

    }

    return 0;
}

从提交记录中找到的,大佬的代码看不懂(就看懂了树状数组函数的一点点,他在函数前加的那些东东是干嘛的?)

回复

3 条回复,欢迎继续交流。

正在加载回复...