QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600351#5000. Balanced Seesaw ArrayYshanqianWA 203ms18040kbC++203.4kb2024-09-29 16:03:362024-09-29 16:03:38

Judging History

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

  • [2024-09-29 16:03:38]
  • 评测
  • 测评结果:WA
  • 用时:203ms
  • 内存:18040kb
  • [2024-09-29 16:03:36]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 10, inf = 1e18;

struct node
{
    int l, r;
    int 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;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    build(1, 1, n);
    while (q--)
    {
        int op, l, r, x;
        cin >> op >> l >> r;
        if (op == 1 || op == 2)
        {
            cin >> x;
            modify(1, l, r, op, x);
        }
        else
        {
            auto [x, y] = query(1, l, r);
            int res1 = x - (l - 1) * y;
            int res2 = y;
            if (res2 == 0)
            {
                if (res1 == res2)
                    cout << "Yes\n";
                else
                    cout << "No\n";
            }
            else
            {
                int k = res1 / res2;
                if (res1 == res2 * k && k >= 1 && k <= r - l + 1)
                    cout << "Yes\n";
                else
                    cout << "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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5644kb

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: 203ms
memory: 18040kb

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'