QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567487#9242. An Easy Geometry Problemucup-team3519WA 16ms9708kbC++204.4kb2024-09-16 12:14:402024-09-16 12:14:40

Judging History

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

  • [2024-09-16 12:14:40]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:9708kb
  • [2024-09-16 12:14:40]
  • 提交

answer

#pragma GCC O(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pi;
#define V vector
#define fi first
#define se second
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end()

const int MN = 2e5 + 1000;

const LL mod = 444445555566666677;
const int base = 233;
LL pbase[MN];
LL tot1[MN];

LL mul(LL a, LL b) {
    return __int128_t(a) * b % mod;
}

LL posi(LL x) {
    if(x < 0) x += mod;
    return x;
}

LL add(LL a, LL b) {
    LL ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans;
}

LL MOD(LL x) {
    if(x < 0) return x + mod;
    if(x >= mod) return x - mod;
    return x;
}

struct node {
    LL hs, rhs;
    LL tag, len;
}seg[MN * 4];

void upd(int x) {
    seg[x].hs = MOD(seg[x * 2].hs + mul(pbase[seg[x * 2].len], seg[x * 2 + 1].hs));
    seg[x].rhs = MOD(seg[x * 2 + 1].rhs + mul(pbase[seg[x * 2 + 1].len], seg[x * 2].rhs));
    seg[x].len = seg[x * 2].len + seg[x * 2 + 1].len;
}

void apply(int x, LL t) {
    seg[x].hs = MOD(seg[x].hs + mul(t, tot1[seg[x].len]));
    seg[x].rhs = MOD(seg[x].rhs + mul(t, tot1[seg[x].len]));
    seg[x].tag += t;
}

void push_down(int x) {
    if(seg[x].tag == 0) return;
    apply(x * 2, seg[x].tag);
    apply(x * 2 + 1, seg[x].tag);
    seg[x].tag = 0;
}

void build(V<int> v) {
    int n = v.size() - 1;
    auto dfs = [&](int x, int l, int r, auto dfs) -> void {
        if(l == r) {
            seg[x].hs = seg[x].rhs = mul(v[l], base);
            seg[x].len = 1;
        }
        else {
            int mid = l + r >> 1;
            dfs(x * 2, l, mid, dfs), dfs(x * 2 + 1, mid + 1, r, dfs);
            upd(x);
        }
    };
    dfs(1, 1, n, dfs);
}
LL query_hs(int x, int l, int r, int ql, int qr) {
    if(ql <= l && qr >= r) {
        return seg[x].hs;
    }
    int mid = l + r >> 1;
    push_down(x);
    LL ans = 0;
    int len = 0;
    if(ql <= mid) ans += query_hs(x * 2, l, mid, ql, qr), len = mid - l + 1;
    if(qr >= mid + 1) ans = MOD(ans + mul(query_hs(x * 2 + 1, mid + 1, r, ql, qr), pbase[len]));
    return ans;
}
LL query_rhs(int x, int l, int r, int ql, int qr) {
    if(ql <= l && qr >= r) {
        return seg[x].rhs;
    }
    int mid = l + r >> 1;
    push_down(x);
    LL ans = 0;
    int len = 0;
    if(qr >= mid + 1) 
        ans += query_rhs(x * 2 + 1, mid + 1, r, ql, qr), len = r - mid;
    if(ql <= mid) 
        ans = MOD(ans + mul(query_rhs(x * 2, l, mid, ql, qr), pbase[len]));
    return ans;
}
void modify(int x, int l, int r, int ql, int qr, LL t) {
    if(ql <= l && qr >= r) {
        apply(x, t);
        return;
    }
    int mid = l + r >> 1;
    push_down(x);
    if(ql <= mid) modify(x * 2, l, mid, ql, qr, t);
    if(qr >= mid + 1) modify(x * 2 + 1, mid + 1, r, ql, qr, t);
    upd(x);
}


void solve() {
    int n; cin >> n;
    int q; cin >> q;
    int k, b; cin >> k >> b;
    V<int> a(n + 1);
    V<LL> should(n + 1);
    should[0] = 0;
    for(int i = 1; i <= n; i++) should[i] = add(mul(posi(k * i + b), pbase[i]), should[i - 1]);

    for(int i = 1; i <= n; i++) cin >> a[i];

    V<int> ini_tree(n + 1);
    for(int i = 1; i <= n; i++) {
        ini_tree[i] = a[i];
    }
    build(ini_tree);

    for(int i = 1; i <= q; i++) {
        int t; cin >> t;
        if(t == 1) {
            int l, r, v; cin >> l >> r >> v;
            modify(1, 1, n, l, r, {v});
        } else {
            int i; cin >> i;
            int l = 0, r = i;
            while(l != r - 1) {
                int mid = l + r >> 1;
                bool ok;
                int len = i - mid;
                if(2 * i - mid > n) ok = 0;
                else {
                    LL hs1 = query_rhs(1, 1, n, mid, i - 1);
                    LL hs2 = query_hs(1, 1, n, i + 1, 2 * i - mid);
                    if(add(mod - hs1, hs2) == should[len]) ok = 1;
                    else ok = 0;
                }
                if(ok) r = mid;
                else l = mid;
            }
            cout << i - r << "\n";
        }
    }
}

int main() {
    pbase[0] = 1;
    for(int i = 1; i <= 2e5 + 10; i++) pbase[i] = mul(pbase[i - 1], base);
    tot1[0] = 0;
    for(int i = 1; i <= 2e5 + 10; i++) tot1[i] = add(tot1[i - 1], pbase[i]);
    ios::sync_with_stdio(0), cin.tie(0);
    // int t; cin >> t;
    int t = 1;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
1
1
1
1
1
2
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
2
1
1
2
1
1
1
1
1
1
1
2
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
2
2
1
1
2
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
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
2
1
1
0
1
1
2
1
1
1
1
1
1
1
1
1
1
1
...

result:

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