QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638001 | #4940. Token Distance | dohoon | WA | 106ms | 27692kb | C++17 | 3.4kb | 2024-10-13 14:36:08 | 2024-10-13 14:36:09 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for (ll i = (a); i <= (b); ++i)
#define per(i,a,b) for (ll i = (b); i >= (a); --i)
#define all(x) begin(x),end(x)
#define siz(x) int(size(x))
#define fi first
#define se second
using namespace std;
using ll = long long;
using vi = vector<ll>;
using ii = pair<ll,ll>;
const ll N = 1e5+3, Q = N;
ll n, q;
multiset<ll> v[N+Q];
array<ll,3> query[Q];
const ll INF = 1e9;
struct node {
ll mn, mx;
ll nxtmn;
ll diff_g;
node(): mn(INF), mx(-INF), nxtmn(INF), diff_g(0) {}
node(ll x, ll y, ll d): mn(x), mx(x), nxtmn(y), diff_g(d) {}
node operator + (const node &rhs) const {
node res;
res.mn = min(mn,rhs.mn);
res.mx = max(mx,rhs.mx);
res.nxtmn = min(nxtmn,rhs.nxtmn);
res.diff_g = gcd(diff_g,rhs.diff_g);
return res;
}
} t[2*N]{};
void upd(ll k, node x) {
k += N;
for (t[k]=x; (k/=2)>=1;) {
t[k] = t[2*k] + t[2*k+1];
}
}
node qry(ll l, ll r) {
node res;
for (l+=N,r+=N; l<=r; ++l/=2,--r/=2) {
if (l&1) res = res+t[l];
if (~r&1) res = res+t[r];
}
return res;
}
ll a[N];
vi vals;
ll nxt(ll x, ll y) { // a[i]=x이면서 y<i인 i의 최솟값
ll X = lower_bound(all(vals), x) - begin(vals);
assert(vals[X] == x);
auto it = v[X].upper_bound(y);
if (it == end(v[X])) return N;
return *it;
}
void init(ll x, ll y) { // a[x]:=y
a[x] = y;
node res(y, nxt(y, x), a[x+1]-a[x]);
upd(x, res);
ll Y = lower_bound(all(vals), y) - begin(vals);
assert(vals[Y] == y);
v[Y].insert(x);
}
void update(ll x, ll y) { // a[x]<-y
ll py = a[x], ny = y;
// delete
ll PY = lower_bound(all(vals), py) - begin(vals);
assert(vals[PY] == py);
auto it = v[PY].find(x);
assert(it != end(v[PY]));
if (it != begin(v[PY])) {
ll i = *prev(it);
upd(i, {a[i], next(it) != end(v[PY]) ? *next(it) : N, a[i+1]-a[i]});
}
v[PY].erase(x);
// add
ll NY = lower_bound(all(vals), ny) - begin(vals);
assert(vals[NY] == ny);
v[NY].insert(x);
a[x] = y;
it = v[NY].find(x);
assert(it != end(v[PY]));
if (it != begin(v[NY])) {
ll i = *prev(it);
upd(i, {a[i], x, a[i+1]-a[i]});
}
upd(x, {a[x], next(it) != end(v[NY]) ? *next(it) : N, a[x+1]-a[x]});
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
rep(i,1,n) cin >> a[i], vals.push_back(a[i]);
rep(i,1,q) {
auto &[x,b,c] = query[i];
cin >> x >> b >> c;
if (x == 1) vals.push_back(c);
}
sort(all(vals)), vals.erase(unique(all(vals)), end(vals));
per(i,1,n) init(i, a[i]);
rep(i,1,q) {
auto [x,b,c] = query[i];
if (x==1) update(b, c);
else {
auto [mn,mx,nmn,dg] = qry(b, c);
if (c-b<=1) cout << "YES\n";
else if (nmn <= c) assert(nmn > b), cout << (mn==mx ? "YES\n" : "NO\n");
else {
assert(mn<mx);
dg = qry(b, c-1).diff_g;
ll len = c - b;
if ((mx-mn)%len) {
cout << "NO\n";
continue;
}
if (dg!=((mx-mn)/len)) cout << "NO\n";
else cout << "YES\n";
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 21608kb
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: 2ms
memory: 22408kb
input:
2 1 0 1000000000 2 1 2
output:
YES
result:
ok single line: 'YES'
Test #3:
score: 0
Accepted
time: 38ms
memory: 26368kb
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: 51ms
memory: 26432kb
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: 34ms
memory: 26064kb
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: 36ms
memory: 26368kb
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: 50ms
memory: 26356kb
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: 72ms
memory: 27116kb
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: 82ms
memory: 27380kb
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: 92ms
memory: 27648kb
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: 0
Accepted
time: 104ms
memory: 27652kb
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 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 45670 lines
Test #12:
score: 0
Accepted
time: 85ms
memory: 27692kb
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 NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES NO YES YES YES YES YES YES YES YES YES NO YES NO YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES YES YES YES YES YE...
result:
ok 45670 lines
Test #13:
score: 0
Accepted
time: 33ms
memory: 26348kb
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 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 #14:
score: -100
Wrong Answer
time: 106ms
memory: 27652kb
input:
96888 91338 595841651 917330480 207421137 35297820 388823033 754743767 175477642 575292540 427299721 685520820 420849096 990712790 335515068 880143917 298720703 665301981 644711586 983560337 804026542 699918615 863609675 666912057 857974409 277769073 133161542 363784287 536671358 866138320 98617155 ...
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:
wrong answer 39481st lines differ - expected: 'NO', found: 'YES'