QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605194#4940. Token DistanceNMK#RE 0ms0kbC++173.5kb2024-10-02 16:03:322024-10-02 16:03:32

Judging History

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

  • [2024-10-02 16:03:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-02 16:03:32]
  • 提交

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, a[N];
multiset<ll> v[N+Q];
array<ll,3> query[Q];
const ll INF = 1e18;

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

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, ll x, ll d) {
    k += N;
    for (t[k]=node(x,nxt(x,k),d); (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;
}

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 &Qry = query[i];
        cin >> Qry[0] >> Qry[1] >> Qry[2];
        if (Qry[0] == 2) vals.push_back(Qry[2]);
    }
    sort(all(vals)), vals.erase(unique(all(vals)), end(vals));
    
    per(i,1,n) {
        insert(a[i], i);
        upd(i,a[i],a[i+1]-a[i]);
    }
    
    rep(i,1,q) {
        auto [x,b,c] = query[i];
        // rep(i,1,n) cerr << nxt(a[i],i) << ' ';
        // cerr << endl;
        if (x==1) { // update
            erase(a[b], b);
            a[b]=c;
            insert(a[b], b);
            upd(b, c, a[b+1]-a[b]);
        } else { // query
            auto [mn,mx,nmn,s,dg] = qry(b, c);
            dg = qry(b, c-1).diff_g;
            // cerr << nmn << endl;
            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 {
                ll len = c - b;
                if ((mx-mn)%len) {
                    // cerr << mn << ' ' << mx << endl;
                    // cerr << len << endl;
                    // cerr << "dbg " << mn << ' ' << mx << ' ' << len << endl;
                    cout << "NO\n";
                    continue;
                }
                if ((mn+mx)*(len+1)/2 != s) {
                    cout << "NO\n";
                } else {
                    // cerr << (mx-mn)/len << endl;
                    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: 0
Runtime Error

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:


result: