QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627697#9242. An Easy Geometry Problemsunyuheng365#WA 7ms26836kbC++145.8kb2024-10-10 16:47:502024-10-10 16:47:53

Judging History

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

  • [2024-10-10 16:47:53]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:26836kb
  • [2024-10-10 16:47:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
// #define int long long
#define mid ((l + r) >> 1)

const int N = 2e5 + 5, base1 = 1500000041, base2 = 1500000043;

using i64 = long long;
template <int MOD>
struct ModInt
{
    int x;
    ModInt() : x(0) {}
    ModInt(i64 y) : x(y >= 0 ? y % MOD : (MOD - (-y) % MOD) % MOD) {}
    inline int inc(const int &x)
    {
        return x >= MOD ? x - MOD : x;
    }
    inline int dec(const int &x)
    {
        return x < 0 ? x + MOD : x;
    }

    ModInt &operator+=(const ModInt &p)
    {
        x = inc(x + p.x);
        return *this;
    }
    ModInt &operator-=(const ModInt &p)
    {
        x = dec(x - p.x);
        return *this;
    }

    ModInt &operator*=(const ModInt &p)
    {
        x = (int)(1ll * x * p.x % MOD);
        return *this;
    }
    ModInt &operator/=(const ModInt &p)
    {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    friend ModInt operator+(const ModInt &lhs, const ModInt &rhs)
    {
        return ModInt(lhs) += rhs;
    }
    friend ModInt operator-(const ModInt &lhs, const ModInt &rhs)
    {
        return ModInt(lhs) -= rhs;
    }
    friend ModInt operator*(const ModInt &lhs, const ModInt &rhs)
    {
        return ModInt(lhs) *= rhs;
    }
    friend ModInt operator/(const ModInt &lhs, const ModInt &rhs)
    {
        return ModInt(lhs) /= rhs;
    }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const
    {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0)
        {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(i64 n) const
    {
        ModInt ret(1), mul(x);
        while (n > 0)
        {
            if (n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p)
    {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a)
    {
        i64 t;
        is >> t;
        a = ModInt<MOD>(t);
        return (is);
    }
    static int get_mod() { return MOD; }
};

using m1 = ModInt<2000000011>;
using m2 = ModInt<2000000033>;

m1 b1[N], pre1[N];
m2 b2[N], pre2[N];

struct TREE
{
    int add;
    int len;
    m1 p1, l1;
    m2 p2, l2;
    TREE operator+(const TREE &t) const
    {
        return {
            0,
            len + t.len,
            p1 * b1[t.len] + t.p1, t.l1 * b1[len] + l1,
            p2 * b2[t.len] + t.p2, t.l2 * b2[len] + l2};
    }
} tr[N << 2];

int c[N];
void settag(int cur, int x)
{
    tr[cur].add += x;
    tr[cur].p1 += pre1[tr[cur].len - 1] * x;
    tr[cur].l1 += pre1[tr[cur].len - 1] * x;
    tr[cur].p2 += pre2[tr[cur].len - 1] * x;
    tr[cur].l2 += pre2[tr[cur].len - 1] * x;
}
void push_down(int cur)
{
    if (tr[cur].add)
    {
        settag(cur * 2, tr[cur].add);
        settag(cur * 2 + 1, tr[cur].add);
        tr[cur].add = 0;
    }
}
void build(int cur, int l, int r)
{
    if (l == r)
        return tr[cur] = {0, 1, c[l], c[l], c[l], c[l]}, void();
    build(cur * 2, l, mid);
    build(cur * 2 + 1, mid + 1, r);
    tr[cur] = tr[cur * 2] + tr[cur * 2 + 1];
}
void change(int cur, int l, int r, int ll, int rr, int x)
{
    if (l == ll && r == rr)
        return settag(cur, x);
    push_down(cur);
    if (rr <= mid)
        change(cur * 2, l, mid, ll, rr, x);
    else if (ll > mid)
        change(cur * 2 + 1, mid + 1, r, ll, rr, x);
    else
        change(cur * 2, l, mid, ll, mid, x), change(cur * 2 + 1, mid + 1, r, mid + 1, rr, x);
    tr[cur] = tr[cur * 2] + tr[cur * 2 + 1];
}
TREE query(int cur, int l, int r, int ll, int rr)
{
    if (l == ll && r == rr)
        return tr[cur];
    push_down(cur);
    if (rr <= mid)
        return query(cur * 2, l, mid, ll, rr);
    else if (ll > mid)
        return query(cur * 2 + 1, mid + 1, r, ll, rr);
    return query(cur * 2, l, mid, ll, mid) + query(cur * 2 + 1, mid + 1, r, mid + 1, rr);
}

int n, q, k, b, a[N];

void solve()
{
    cin >> n >> q >> k >> b;
    b *= 2;
    for (int i = 1; i <= n; i++)
        cin >> a[i], a[i] *= 2;
    for (int i = 1; i <= n; i++)
        c[i] = a[i] + 4e8 + k * (n - i + 1);
    b1[0] = 1, b2[0] = 1, pre1[0] = 1, pre2[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        b1[i] = b1[i - 1] * base1, pre1[i] = pre1[i - 1] + b1[i];
        b2[i] = b2[i - 1] * base2, pre2[i] = pre2[i - 1] + b2[i];
    }
    build(1, 1, n);
    for (int i = 1; i <= q; i++)
    {
        int opt;
        cin >> opt;
        if (opt == 1)
        {
            int l, r, x;
            cin >> l >> r >> x;
            x *= 2;
            change(1, 1, n, l, r, x);
        }
        else
        {
            int pos;
            cin >> pos;
            int bot = 1, top = min(n - pos, pos - 1), ans = 0;
            while (bot <= top)
            {
                int m = ((bot + top) >> 1);
                TREE le = query(1, 1, n, pos - m, pos - 1);
                TREE re = query(1, 1, n, pos + 1, pos + m);
                if (le.l1 + b * pre1[m - 1] == re.p1 && le.l2 + b * pre2[m - 1] == re.p2)
                    ans = m, bot = m + 1;
                else
                    top = m - 1;
            }
            std::cout << ans << endl;
        }
    }
}

signed main()
{
#ifndef sunyuheng365
    ios::sync_with_stdio(false);
#endif
    int tc = 1;
    // cin >> tc;
    while (tc--)
        solve();
#ifdef sunyuheng365
    system("pause");
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
3
2
3
3
5
5
4
3
4
3
4
4
3
3
6
3
3
3
3
3
3
3
7
3
3
3
1
4
5
2
5
2
5
3
4
5
4
3
4
1
3
3
3
5
4
4
3
5
1
3
4
3
2
2
3
4
5
2
4
2
5
2
3
3
5
3
3
3
8
3
5
10
3
2
4
3
4
3
3
3
2
3
3
3
8
3
3
1
3
3
4
3
2
7
3
5
3
3
3
5
3
11
3
4
4
4
7
3
2
3
3
4
3
3
3
4
3
3
2
3
3
2
6
3
4
3
3
3
3
4
3
7
2
4
0
3
3
5
3
5
2
1
4
3
2
4
2
2
...

result:

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