QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#552043#9242. An Easy Geometry Problemucup-team3519#WA 46ms8160kbC++204.7kb2024-09-07 20:01:462024-09-07 20:01:46

Judging History

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

  • [2024-09-07 20:01:46]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:8160kb
  • [2024-09-07 20:01:46]
  • 提交

answer

#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) {
    LL res = a * b - LL(1.L * a * b / mod) * mod;
    res %= mod;
    if (res < 0) {
        res += mod;
    }
    return res;
}

LL qpow(LL a, LL k) {
	LL ans = 1;
	while (k) {
		if (k & 1) ans = mul(ans, a);
		k >>= 1;
		a = mul(a, a);
	}
	return ans;
}

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;
}

struct info {
    int len;
    LL hs, rhs;
}i0{0, 0, 0};

struct tag {
    LL add;
}t0{0};

struct node {
    info i;
    tag t;
}seg[MN * 4];

info operator+(info a, info b) {
    return {a.len + b.len, add(a.hs, mul(b.hs, pbase[a.len])), add(b.rhs, mul(a.rhs, pbase[b.len]))};
}
info operator + (info a, tag t) {
    return {a.len, add(a.hs, mul(tot1[a.len], posi(t.add)))};
}
tag operator +(tag a, tag b) {
    return {a.add + b.add};
}

void upd(int x) {
    seg[x].i = seg[x * 2].i + seg[x * 2 + 1].i;
}

void push_down(int x) {
    if(seg[x].t.add == 0) return;
    seg[x * 2].i = seg[x * 2].i + seg[x].t;
    seg[x * 2 + 1].i = seg[x * 2 + 1].i + seg[x].t;
    seg[x * 2].t = seg[x * 2].t + seg[x].t;
    seg[x * 2 + 1].t = seg[x * 2 + 1].t + seg[x].t;
    seg[x].t = t0;
}

void build(V<info> v) {
    int n = v.size() - 1;
    auto dfs = [&](int x, int l, int r, auto dfs) -> void {
        if(l == r) seg[x].i = v[l];
        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);
}
info query(int x, int l, int r, int ql, int qr) {
    if(ql <= l && qr >= r) {
        return seg[x].i;
    }
    int mid = l + r >> 1;
    push_down(x);
    info ans = i0;
    if(ql <= mid) ans = ans + query(x * 2, l, mid, ql, qr);
    if(qr >= mid + 1) ans = ans + query(x * 2 + 1, mid + 1, r, ql, qr);
    return ans;
}
void modify(int x, int l, int r, int ql, int qr, tag t) {
    if(ql <= l && qr >= r) {
        seg[x].i = seg[x].i + t;
        seg[x].t = seg[x].t + 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(k * i + b, pbase[i]), should[i - 1]);

    // cout << should[1] << endl;

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

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

    // cout << ini_tree[3].rhs << endl;
    // cout << tot1[1] * 10 << endl;

    auto f = [&](int x) -> int {
        return x * k + b;
    };
    // cout << f(2) << endl;

    // cout << add(query(1, 1, n, 3, 3).hs, mod - query(1, 1, n, 1, 1).rhs) - should[1] << endl;

    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(1, 1, n, mid, i - 1).rhs;
                    LL hs2 = query(1, 1, n, i + 1, 2 * i - mid).hs;
                    if(add(mod - hs1, hs2) == should[len]) ok = 1;
                    else ok = 0;
                }
                if(ok) r = mid;
                else l = mid;
            }
            cout << i - r << "\n";
        }
        // for(int i = 1; i <= n; i++) cout << query(1, 1, n, i, i).hs / base << " ";
        // cout << "debug : " << query(1, 1, n, 1, 2).rhs << " " << query(1, 1, n, 4, 5).hs << " " << should[2] << endl;
        // cout << endl;
    }

}

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();
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 7748kb

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

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
304
73
29
61
292
139
48
17
99
6
5
53
93
3
91
65
29
33
306
21
24
17
21
281
12
16
1
33
7
18
96
7
40
39
13
7
46
43
16
1
72
33
16
22
5
6
189
27
1
35
107
43
34
3
27
20
21
44
56
96
36
2
27
22
30
32
6
5
105
27
37
12
58
2
21
154
17
110
57
3
7
33
15
24
94
68
25
1
14
10
4
10
2
25
39
36
33
164
11
19
181
11
3...

result:

wrong answer 349th numbers differ - expected: '25', found: '0'