吸氧错,不吸氧对,求原因

P1314 [NOIP2011 提高组] 聪明的质监员

nyllsom @ 2024-07-04 11:22:56

85pts,出现一个非常离谱的问题

第十个数据点吸氧错,不吸氧就能过

本地跑出来是对的

极度让人迷惑!

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline ll read() {
    ll x = 0, f = 1; char c = getchar();
    while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
    while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
    return f * x;
}
void write(ll x) { if (x >= 10) write(x / 10); putchar('0' + x % 10); }

int n, m;   
ll s;
int W[200010], V[100010];
int lbian[200010], rbian[100010];
int prenum[200010];
ll presum[200010];
ll tmpans, ans;

void chk(ll w) {
    for (int i = 1; i <= n; i++) {
        prenum[i] = prenum[i - 1] + (W[i] >= w ? 1 : 0);
        presum[i] = presum[i - 1] + (W[i] >= w ? V[i] : 0);
    }
    for (int i = 1; i <= m; i++) {
        tmpans += 1ll * (prenum[rbian[i]] - prenum[lbian[i] - 1]) * (presum[rbian[i]] - presum[lbian[i] - 1]);
    }
}

int main() {

//  freopen("P1314_10.in", "r", stdin);

    n = read(), m = read(), s = read();
    int l = 1, r = -1e9;
    for (int i = 1; i <= n; i++) {
        W[i] = read(), V[i] = read();
        r = max(r, W[i]);
    }
    for (int i = 1; i <= m; i++) {
        lbian[i] = read(), rbian[i] = read();
    }
    ans = 1e18;
    while (l <= r) {
        int mid = l + r >> 1;
        tmpans = 0;
        chk(mid);
        ans = min(ans, (tmpans - s >= 0 ? tmpans - s : s - tmpans));
        if (tmpans > s) l = mid + 1;
        else if (tmpans < s) r = mid - 1;
        else break;
    }
    printf("%lld\n", ans);
    return 0;
}

by wfirstzhang @ 2024-07-04 11:32:18

数组开小了。开 262144 就过了。


|