QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605372 | #4940. Token Distance | NMK# | WA | 0ms | 23248kb | C++17 | 3.1kb | 2024-10-02 16:53:33 | 2024-10-02 16:53:34 |
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 = 1e18;
struct node {
ll mn, mx;
ll nxtmn, sum;
ll diff_g;
node(): mn(INF), mx(-INF), nxtmn(INF), sum(0ll), diff_g(0) {}
node(ll x, ll y, ll d): mn(x), mx(x), nxtmn(y), sum(x), 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.sum = sum+rhs.sum;
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) { // 값 x에서 인덱스 y 다음으로 오는 첫 인덱스
ll i = lower_bound(all(vals), x) - begin(vals);
auto it = v[i].upper_bound(y);
return it == v[i].end() ? N : *it;
}
void erase(ll x, ll y) {
ll i = lower_bound(all(vals), x) - begin(vals);
v[i].erase(y);
}
void insert(ll x, ll y) {
ll i = lower_bound(all(vals), x) - begin(vals);
v[i].insert(y);
}
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 &[a,b,c] = query[i];
cin >> a >> b >> c;
if (a == 2) vals.push_back(c);
}
sort(all(vals)), vals.erase(unique(all(vals)), end(vals));
per(i,1,n) {
insert(a[i], i);
upd(i, {a[i], nxt(a[i],i), a[i+1]-a[i]});
}
rep(i,1,q) {
auto [x,b,c] = query[i];
if (x==1) { // update
erase(a[b], b);
a[b]=c;
insert(a[b], b);
upd(b, {c, nxt(c,b), b==n?0ll:a[b+1]-c});
} else { // query
auto [mn,mx,nmn,s,dg] = qry(b, c);
if (c-b<=1) {
cout << "YES\n";
}
else if (nmn <= c) {
assert(nmn > b);
if (mn == mx) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
dg = qry(b, c-1).diff_g;
ll len = c - b;
if ((mx-mn)%len) {
cout << "NO\n";
continue;
}
if ((mn+mx)*(len+1)/2 != s) {
cout << "NO\n";
} else {
if (dg!=((mx-mn)/len)) cout << "NO\n";
else cout << "YES\n";
}
}
}
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 23248kb
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 NO YES
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'