QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130821 | #4940. Token Distance | karuna# | RE | 1ms | 5532kb | C++17 | 3.6kb | 2023-07-25 11:30:34 | 2023-07-25 11:30:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101010;
const int INF = 1e9 + 10;
int n, q, a[MAXN];
struct seg {
array<int, 3> tree[MAXN];
bool g = false;
void update(int a, int v, int l, int r, int x) {
if (l == r) {
tree[x] = {v, v, v};
return;
}
int m = (l + r) / 2;
if (a <= m) update(a, v, l, m, 2 * x);
else update(a, v, m + 1, r, 2 * x + 1);
auto [m1, M1, g1] = tree[2 * x];
auto [m2, M2, g2] = tree[2 * x + 1];
if (g) {
tree[x] = {min(m1, m2), max(M1, M2), __gcd(g1, g2)};
}
else {
tree[x] = {min(m1, m2), max(M1, M2), 0};
}
}
int query(int a, int b, int t, int l, int r, int x) {
if (b < l || a > r) {
return vector<int>{INF, -INF, 0}[t];
}
if (a <= l && r <= b) return tree[x][t];
int m = (l + r) / 2;
int r1 = query(a, b, t, l, m, 2 * x);
int r2 = query(a, b, t, m + 1, r, 2 * x + 1);
if (t == 0) return min(r1, r2);
else if (t == 1) return max(r1, r2);
else return __gcd(r1, r2);
}
} t1, t2, t3;
set<pair<int, int>> st;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> q;
t2.g = true;
for (int i = 1; i <= n; i++) {
cin >> a[i];
t1.update(i, a[i], 1, n, 1);
if (i != 1) {
t2.update(i, a[i] - a[i - 1], 2, n, 1);
}
st.insert({a[i], i});
}
for (auto it = st.begin(); it != st.end(); it = next(it)) {
if (it != st.begin() && prev(it)->first == it->first)
t3.update(it->second, prev(it)->second, 1, n, 1);
}
while (q--) {
int t; cin >> t;
if (t == 1) {
int x, v; cin >> x >> v;
auto it = st.find({a[x], x});
if (it != st.begin() && prev(it)->first == it->first) {
t3.update(it->second, 0, 1, n, 1);
}
if (it != st.end() && it->first == next(it)->first) {
t3.update(next(it)->second, 0, 1, n, 1);
}
st.erase({a[x], x});
a[x] = v;
t1.update(x, v, 1, n, 1);
if (x != 1) t2.update(x, a[x] - a[x - 1], 2, n, 1);
if (x != n) t2.update(x + 1, a[x + 1] - a[x], 2, n, 1);
it = st.insert({v, x}).first;
if (it != st.begin() && prev(it)->first == it->first) {
t3.update(it->second, prev(it)->second, 1, n, 1);
}
if (it != st.end() && it->first == next(it)->first) {
t3.update(next(it)->second, it->second, 1, n, 1);
}
}
else {
int l, r; cin >> l >> r;
int m = t1.query(l, r, 0, 1, n, 1);
int M = t1.query(l, r, 1, 1, n, 1);
if (m == M) {
cout << "YES\n";
}
else {
if ((M - m) % (r - l) != 0) {
cout << "NO\n";
}
else {
int D = (M - m) / (r - l);
int g = t2.query(l + 1, r, 2, 2, n, 1);
if (g % D != 0) {
cout << "NO\n";
}
else {
int x = t3.query(l, r, 1, 1, n, 1);
if (x >= l)
cout << "NO\n";
else
cout << "YES\n";
}
}
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5488kb
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: 1ms
memory: 5532kb
input:
2 1 0 1000000000 2 1 2
output:
YES
result:
ok single line: 'YES'
Test #3:
score: -100
Runtime Error
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...