P3374 | 快读错误求调(悬2关
  • 板块题目总版
  • 楼主lyb_qhd
  • 当前回复4
  • 已保存回复4
  • 发布时间2025/7/20 08:36
  • 上次更新2025/7/20 15:54:17
查看原帖
P3374 | 快读错误求调(悬2关
1476288
lyb_qhd楼主2025/7/20 08:36

100pts WA on #1. 代码:

#include<bits/stdc++.h>
#define fil [[gnu::always_inline]] inline
#define up(i,l,r) for(long long i=(l),E##i=(r);i<=E##i;++i)
#define dn(i,r,l) for(long long i=(r),E##i=(l);i>=E##i;--i)
using namespace std; typedef long long ll;
constexpr ll MAXB = 710, N = 5 + 5e5 + 2 * MAXB;

ll n, B, C;
array<ll, N> a, m;
array<ll, MAXB> b, l, r;

fil ll ri();
fil void build(), add(ll, ll), query(ll, ll);

int main() {
    ll q, t, x, y;

    n = ri(); q = ri();
    up (i, 1, n) a[i] = ri();
    build();
    // up (i, 1, n) printf("|%lld %lld %lld \n", i, a[i], m[i]);
    // up (i, 1, C) printf("|%lld %lld %lld %lld \n", i, b[i], l[i], r[i]);
    while (q--) {
        t = ri(); x = ri(); y = ri();
        // printf("|%lld %lld %lld \n", t, x, y);
        (t == 1) ? add(x, y) : query(x, y);
    }
}

fil void build() {
    B = ceil(sqrtl(n)); C = (n + B - 1) / B;
    up (j, 1, C - 1) up (i, l[j] = r[j - 1] + 1, r[j] = j * B) {
        m[i] = j;
        b[j] += a[i];
    }
    up (i, l[C] = r[C-1]+1, r[C] = n) {
        m[i] = C;
        b[C] += a[i];
    }
    // printf("|%lld %lld %lld %lld\n",B,C,l[C],r[C]);
}
fil void add(ll i, ll x) {
    a[i] += x;
    b[m[i]] += x;
}
fil ll rget(ll x, ll y, ll ret = 0) {
    up (i, x, y) ret += a[i];
    return ret;
}
fil void query(ll x, ll y) {
    if (m[x] == m[y]) return (void) printf("%lld\n", rget(x, y));
    ll ret = rget(x, r[m[x]]) + rget(l[m[y]], y);
    for (ll j = m[x] + 1; j < m[y]; ++j) ret += b[j];
    printf("%lld\n", ret);
}

#define g (p==q?q=(p=b)+fread(b,1,sizeof b,stdin),c=*(p++):(c=*(p++)))
inline ll ri() {
    static char b[1 << 20], *p = b, *q = b, c = 0;
    static ll x; static bool s;
    for (x = s = 0; '0' > c || c > '9'; g) if (c == '-') s = !s;
    while ('0' <= c && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'), g;
    return s ? -x : x;
}
#undef g

评测结果:https://www.luogu.com.cn/record/225535197

以下是读入测试,疑似为WA原因。

代码:

#include<bits/stdc++.h>
#define fil [[gnu::always_inline]] inline
#define up(i,l,r) for(long long i=(l),E##i=(r);i<=E##i;++i)
#define dn(i,r,l) for(long long i=(r),E##i=(l);i>=E##i;--i)
using namespace std; typedef long long ll;
constexpr ll N = 5 + 5e5;

ll n;
array<ll, N> a;
inline ll ri();
int main() {
    ll q, t, x, y;

    n = ri(); q = ri();
    up (i, 1, n) a[i] = ri();
    while (q--) {
        t = ri(); x = ri(); y = ri();
        printf("|%lld %lld %lld \n", t, x, y);
    }
}

#define g (p==q?q=(p=b)+fread(b,1,sizeof b,stdin),c=*(p++):(c=*(p++)))
inline ll ri() {
    static char b[1 << 20], *p = b, *q = b, c = 0;
    static ll x; static bool s;
    for (x = s = 0; '0' > c || c > '9'; g) if (c == '-') s = !s;
    while ('0' <= c && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'), g;
    return s ? -x : x;
}
#undef g

输入(#1):

25 7
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1
2 25 25
1 7 9
2 7 7
2 6 7
2 7 8
2 6 8

本地输出:

|2 1 1
|2 25 25
|1 7 9
|2 7 7
|2 6 7
|2 7 8
|2 6 8

本地C++版本:g++14

g++.exe (x86_64-win32-seh-rev2, Built by MinGW-Builds project) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

洛谷IDE(猜测包括评测机)输出:

|2 1 1 
|2 25 25 
|1 7 9 
|2 7 7 
|2 6 7 
|2 7 8 
|2 6 825

C++14/C++14(GCC9)均如此。

违规自删。

2025/7/20 08:36
加载中...