关于我提交时的一些奇怪情况
查看原帖
关于我提交时的一些奇怪情况
513009
lmjsjg楼主2022/5/7 21:20

AC 代码如下:

#include<cstdio>
#include<cctype>
#include<cmath>
#include<iostream>

using namespace std;
typedef long long ll;

ll read() {
    ll x = 0, y = 1;
    char ch = getchar();

    while(!isdigit(ch)) {
        if(ch == '-') {
            y = -1;
        }
        ch = getchar();
    }

    while(isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }

    return x * y;
}

const int MAXN = 200005;

ll n, q, s, t, dif[MAXN], b, last, now;

inline ll get_b(ll now_dif) {
    if(now_dif > 0) {
        return -(s * abs(now_dif));
    } else if(now_dif < 0) {
        return t * abs(now_dif);
    } else {
        return 0;
    }
}

int main() {
    n = read(), q = read(), s = read(), t = read();
    for(int i = 0; i <= n; ++i) {
        now = read();
        dif[i] = now - last;
        last = now;
        b += get_b(dif[i]);
    }

    for(int i = 1; i <= q; ++i) {
        ll x, y, z;
        x = read(), y = read(), z = read();

        b -= get_b(dif[x]);
        dif[x] += z;
        b += get_b(dif[x]);

        if(y < n) {
            b -= get_b(dif[y + 1]);
            dif[y + 1] -= z;
            b += get_b(dif[y + 1]);
        }

        printf("%lld\n", b);
    }

    return 0;
}

一开始我没有加 using namespace std,点2总是 W 掉;加上该语句后成功 AC。这是怎么回事?

2022/5/7 21:20
加载中...