QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719325#9242. An Easy Geometry ProblemYipChipWA 54ms8436kbC++234.0kb2024-11-07 00:17:062024-11-07 00:17:06

Judging History

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

  • [2024-11-07 00:17:06]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:8436kb
  • [2024-11-07 00:17:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int N = 2e5 + 10;
const ll base = 1145141;
int n, q, k, b;
ull a[N], mi[N], pre[N];
struct Node
{
    int l, r;
    ull sum1, sum2, add1, add2;
}tr[N << 2];

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 pushdown(int u)
{
    if (tr[u].add1)
    {
        tr[u << 1].add1 += tr[u].add1, tr[u << 1 | 1].add1 += tr[u].add1;
        tr[u << 1].sum1 += pre[tr[u << 1].r - tr[u << 1].l] * mi[tr[u << 1].l] * tr[u].add1;
        tr[u << 1 | 1].sum1 += pre[tr[u << 1 | 1].r - tr[u << 1 | 1].l] * mi[tr[u << 1 | 1].l] * tr[u].add1;
        tr[u].add1 = 0;
    }
    if (tr[u].add2)
    {
        ull len = tr[u << 1].r - tr[u << 1].l + 1;
        tr[u << 1].add2 += tr[u].add2, tr[u << 1 | 1].add2 += tr[u].add2;
        tr[u << 1].sum2 += pre[tr[u << 1].r - tr[u << 1].l] * mi[tr[u << 1].l] * tr[u].add2;
        tr[u << 1 | 1].sum2 += pre[tr[u << 1 | 1].r - tr[u << 1 | 1].l] * mi[tr[u << 1 | 1].l] * tr[u].add2;
        tr[u].add2 = 0;
    }
}

void modify1(int u, int l, int r, ull d)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        tr[u].sum1 += d * pre[tr[u].r - tr[u].l] * mi[tr[u].l];
        tr[u].add1 += d;
        return;
    }
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    if (l <= mid) modify1(u << 1, l, r, d);
    if (r > mid) modify1(u << 1 | 1, mid + 1, r, d);
    pushup(u);
}

void modify2(int u, int l, int r, ull d)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        tr[u].sum2 += d * pre[tr[u].r - tr[u].l] * mi[tr[u].l];
        tr[u].add2 += d;
        return;
    }
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    if (l <= mid) modify1(u << 1, l, r, d);
    if (r > mid) modify1(u << 1 | 1, mid + 1, r, d);
    pushup(u);
}

ull query1(int u, int l, int r)
{
    if (tr[u].l == tr[u].r) return tr[u].sum1;
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    ull res = 0;
    if (l <= mid) res = query1(u << 1, l, r);
    if (r > mid) res += query1(u << 1 | 1, l, r);
    return res;
}

ull query2(int u, int l, int r)
{
    if (tr[u].l == tr[u].r) return tr[u].sum2;
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    ull res = 0;
    if (l <= mid) res = query2(u << 1, l, r);
    if (r > mid) res += query2(u << 1 | 1, l, r);
    return res;
}

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

bool check(int x, int r)
{
    ull res1 = query1(1, x + 1, x + r);
    ull res2 = query2(1, n - x + 2, n - x + r + 1);
    return res1 * mi[n - x + 1] == res2 * mi[x];
}

void solve()
{
    cin >> n >> q >> k >> b;
    for (int i = 1; i <= n; i ++ ) cin >> a[i], a[i] = 2 * a[i] - i * k;
    pre[0] = mi[0] = 1;
    for (int i = 1; i <= n; i ++ ) mi[i] = mi[i - 1] * base;
    for (int i = 1; i <= n; i ++ ) pre[i] += pre[i - 1] + mi[i];
    build(1, 1, n);
    while (q -- )
    {
        int op, l, r, x;
        cin >> op;
        if (op == 1)
        {
            cin >> l >> r >> x;
            modify1(1, l, r, x << 1);
            modify2(1, n - r + 1, n - l + 1, x << 1);
        }
        else
        {
            cin >> x;
            l = 1, r = min(n - x, x - 1);
            int ans = 0;
            while (l <= r)
            {
                int mid = l + r >> 1;
                if (check(x, mid)) l = mid + 1, ans = mid;
                else r = mid - 1;
            }
            cout << ans << "\n";
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    while (T -- ) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7660kb

input:

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4

output:

1
0
2
0

result:

ok 4 number(s): "1 0 2 0"

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 8436kb

input:

5000 5000 2 0
-329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...

output:

2
0
0
0
0
0
0
0
116
0
0
0
0
0
0
0
0
0
0
0
0
22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
32
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
15
7
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
17
0
0
0
0
0
0
0
0
0...

result:

wrong answer 2nd numbers differ - expected: '304', found: '0'