QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600384#5000. Balanced Seesaw ArrayYshanqianWA 319ms31476kbC++203.9kb2024-09-29 16:11:412024-09-29 16:11:41

Judging History

你现在查看的是最新测评结果

  • [2024-09-29 16:11:41]
  • 评测
  • 测评结果:WA
  • 用时:319ms
  • 内存:31476kb
  • [2024-09-29 16:11:41]
  • 提交

answer

#include <bits/stdc++.h>
#define int __int128
#define endl '\n'
using namespace std;
typedef pair<__int128, __int128> pii;
const int N = 2e5 + 10, inf = 1e18;
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}
struct node
{
    int l, r;
    __int128 sum1, sum2;
    int lazy1, lazy2;
} tr[N << 2];
int a[N];

void pushup(int u)
{
    tr[u].sum1 = tr[u << 1].sum1 + tr[u << 1 | 1].sum1;
    tr[u].sum2 = tr[u << 1].sum2 + tr[u << 1 | 1].sum2;
}

void build(int u, int l, int r)
{
    tr[u] = {l, r, 0, 0, 0, 0};
    if (l == r)
    {
        tr[u].sum1 = a[l] * l;
        tr[u].sum2 = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    pushup(u);
}

void change(int u, int op, int x)
{
    if (op == 1)
    {
        tr[u].sum1 += x * (tr[u].r * (tr[u].r + 1) / 2 - tr[u].l * (tr[u].l - 1) / 2);
        tr[u].sum2 += (tr[u].r - tr[u].l + 1) * x;
        tr[u].lazy2 = 0;
        tr[u].lazy1 += x;
    }
    else
    {
        tr[u].sum1 = x * (tr[u].r * (tr[u].r + 1) / 2 - tr[u].l * (tr[u].l - 1) / 2);
        tr[u].sum2 = (tr[u].r - tr[u].l + 1) * x;
        tr[u].lazy1 = 0;
        tr[u].lazy2 = x;
    }
}

void pushdown(int u)
{
    if (tr[u].lazy1)
    {
        change(u << 1, 1, tr[u].lazy1);
        change(u << 1 | 1, 1, tr[u].lazy1);
        tr[u].lazy1 = 0;
    }
    if (tr[u].lazy2)
    {
        change(u << 1, 2, tr[u].lazy2);
        change(u << 1 | 1, 2, tr[u].lazy2);
        tr[u].lazy2 = 0;
    }
}

void modify(int u, int l, int r, int op, int x)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        change(u, op, x);
        return;
    }
    int mid = (tr[u].l + tr[u].r) >> 1;
    pushdown(u);
    if (l <= mid)
        modify(u << 1, l, r, op, x);
    if (r > mid)
        modify(u << 1 | 1, l, r, op, x);
    pushup(u);
}

pii query(int u, int l, int r)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        return {tr[u].sum1, tr[u].sum2};
    }
    int mid = (tr[u].l + tr[u].r) >> 1;
    pushdown(u);
    int res1 = 0, res2 = 0;
    if (l <= mid)
    {
        pii xx = query(u << 1, l, r);
        res1 += xx.first;
        res2 += xx.second;
    }
    if (r > mid)
    {
        pii xx = query(u << 1 | 1, l, r);
        res1 += xx.first;
        res2 += xx.second;
    }
    return {res1, res2};
}

void solve()
{
    int n, q;
    n = read();
    q = read();
    for (int i = 1; i <= n; i++)
        a[i] = read();
    build(1, 1, n);
    while (q--)
    {
        int op, l, r, x;
        op = read();
        l = read();
        r = read();
        if (op == 1 || op == 2)
        {
            x = read();
            modify(1, l, r, op, x);
        }
        else
        {
            auto [x, y] = query(1, l, r);
            __int128 res1 = x - (l - 1) * y;
            __int128 res2 = y;
            if (res2 == 0)
            {
                if (res1 == res2)
                    printf("Yes\n");
                else
                    printf("No\n");
            }
            else
            {
                __int128 k = res1 / res2;
                if (res1 == res2 * k && k >= 1 && k <= r - l + 1)
                    printf("Yes\n");
                else
                    printf("No\n");
            }
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);

    int t = 1;
    //    cin>>t;
    while (t--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5600kb

input:

3 6
1 2 3
3 1 1
3 1 3
1 1 1 2
3 1 3
2 2 2 0
3 2 3

output:

Yes
No
Yes
Yes

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 319ms
memory: 31476kb

input:

100000 451163
-18 609 -793 393 375 313 -55 -892 -446 928 -207 -390 729 -383 27 318 -400 31 -661 202 -978 212 238 -368 351 -613 -23 400 809 1000 -431 -174 -103 886 73 -150 25 820 -689 972 777 794 -36 -231 -966 632 -418 -288 -476 725 -713 -379 896 -19 -883 338 -797 937 -557 -809 -241 -539 704 44 576 -...

output:

No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
N...

result:

wrong answer 9th lines differ - expected: 'Yes', found: 'No'