QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#315870#4940. Token Distanceqwq7WA 50ms12312kbC++232.2kb2024-01-27 16:14:122024-01-27 16:14:13

Judging History

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

  • [2024-01-27 16:14:13]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:12312kb
  • [2024-01-27 16:14:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
using i128 = __int128;

const int N = 100010;
const i64 mod = 1e18 + 9;

struct Info {
    int mn, mx;
    i64 s1, s2;
    Info() = default;
    Info(int x) {
        mn = mx = s1 = x;
        s2 = 1ll * x * x % mod;
    }
};

Info operator+(Info a, Info b) {
    Info c;
    c.mn = min(a.mn, b.mn);
    c.mx = max(a.mx, b.mx);
    c.s1 = (a.s1 + b.s1) % mod;
    c.s2 = (a.s2 + b.s2) % mod;
    return c;
}

struct Node {
	int l, r;
	Info info;
} tr[N << 2];
int n, m, w[N];

void pushup(int u) {
    tr[u].info = tr[u << 1].info + tr[u << 1 | 1].info;
}

void build(int u, int l, int r) {
	tr[u] = {l, r, Info(w[l])};
	if (l == r) return;
	int mid = l + r >> 1;
	build(u << 1, l, mid);
	build(u << 1 | 1, mid + 1, r);
	pushup(u);
}

void modify(int u, int x, int v) {
	if (tr[u].l == tr[u].r) return tr[u].info = Info(v), void();
	int mid = tr[u].l + tr[u].r >> 1;
	if (x <= mid) modify(u << 1, x, v);
	else modify(u << 1 | 1, x, v);
	pushup(u);
}

Info query(int u, int l, int r) {
	if (tr[u].l >= l && tr[u].r <= r) return tr[u].info;
	int mid = tr[u].l + tr[u].r >> 1;
	if (r <= mid) return query(u << 1, l, r);
	if (l > mid) return query(u << 1 | 1, l, r);
	return query(u << 1, l, r) + query(u << 1 | 1, l, r);
}

const i64 inv2 = (mod + 1) / 2;

i64 sum(int n, int s, int d) {
    i64 ans = i128(6) * n * s * s % mod;
    (ans += i128(6) * d * (n + 1) * n * s % mod) %= mod;
    (ans += i128(1) * n * (n + 1) * (2 * n + 1) % mod * d * d % mod) %= mod;
    return ans;
}

int main() {
	cin.tie(0)->sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> w[i];
	build(1, 1, n);
	while (m--) {
	    int op, x, y;
	    cin >> op >> x >> y;
	    if (op == 1) {
	        modify(1, x, y);
	    } else {
	        auto [mn, mx, s1, s2] = query(1, x, y);
	        int t = y - x;
	        if ((mx - mn) % t) {
	            cout << "NO\n";
	            continue;
	        }
	        int d = (mx - mn) / t;
        	i64 tar1 = 1ll * (mn + mx) * (t + 1) / 2 % mod;
			i64 tar2 = sum(y - x + 1, mn - d, d);
	        if (pair(s1, 6ll * s2 % mod) == pair(tar1, tar2)) {
	            cout << "YES\n";
	        } else {
	            cout << "NO\n";
	        }
	    }
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7
1 1 1 10 1
2 1 3
2 1 5
1 5 4
1 3 7
2 2 4
2 2 5
2 4 5

output:

YES
NO
NO
YES
YES

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2 1
0 1000000000
2 1 2

output:

YES

result:

ok single line: 'YES'

Test #3:

score: 0
Accepted
time: 14ms
memory: 12048kb

input:

81473 13549
972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...

output:

YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
Y...

result:

ok 4517 lines

Test #4:

score: 0
Accepted
time: 8ms
memory: 12120kb

input:

81473 13549
994993061 993089286 973546017 983608065 980300695 994305454 992559601 974765838 987574661 988923180 987601637 991357764 981678157 994388630 987066613 976087381 985770922 989296067 975698758 977548300 992236732 978102432 983875296 979745439 977111907 992622264 988921213 987697458 99145442...

output:

NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES...

result:

ok 4517 lines

Test #5:

score: 0
Accepted
time: 11ms
memory: 12068kb

input:

81473 13549
972586964 972586683 972587526 972587245 972588088 972587807 972588650 972588369 972589212 972588931 972589774 972589493 972590336 972590055 972590898 972590617 972591460 972591179 972592022 972591741 972592584 972592303 972593146 972592865 972593708 972593427 972594270 972593989 97259483...

output:

NO
NO
YES
YES
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES...

result:

ok 13549 lines

Test #6:

score: 0
Accepted
time: 16ms
memory: 12296kb

input:

81473 13549
136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 13549 lines

Test #7:

score: 0
Accepted
time: 15ms
memory: 12108kb

input:

81473 13549
136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...

output:

YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
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
YES
NO
NO
NO
YES
NO
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
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO...

result:

ok 6727 lines

Test #8:

score: 0
Accepted
time: 49ms
memory: 12132kb

input:

96888 91338
0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 91338 lines

Test #9:

score: 0
Accepted
time: 50ms
memory: 12116kb

input:

96888 91338
0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...

output:

NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YE...

result:

ok 91338 lines

Test #10:

score: 0
Accepted
time: 46ms
memory: 12312kb

input:

96888 91338
0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...

output:

YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
YES
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
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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 45670 lines

Test #11:

score: -100
Wrong Answer
time: 26ms
memory: 12124kb

input:

96888 91338
148622400 313851289 796564459 844340368 558593162 622118917 828177682 162586713 809187042 120384144 635536217 253999810 681392420 868894027 212922230 762102640 996956995 352833706 345175524 294127858 22179829 707700649 122520591 837858780 906906270 596853109 3416251 593901303 130684502 8...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer 2nd lines differ - expected: 'YES', found: 'NO'