QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225183#4940. Token DistanceBUET_TwilightWA 59ms36484kbC++237.2kb2023-10-24 03:54:462023-10-24 03:54:47

Judging History

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

  • [2023-10-24 03:54:47]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:36484kb
  • [2023-10-24 03:54:46]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
#define int long long
#define ll long long 
#define lll __int128_t
#define pb push_back
// #define double long double
#define pii pair<int,int>
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

const int N = 1002;
int MX = N * 10;
int dp[N][2][N*10];

struct SegmentTree {
    vector<int> a;
    vector<pii> t;
    int n;

    pii merge(pii a, pii b) {
        return {max(a.first, b.first), min(a.second, b.second)};
    }

    SegmentTree(const vector<long long>& arr) {
        a = arr;
        n = a.size();
        t = vector<pii>(4 * n+1);
        build(1, 0, n-1);
    }

    SegmentTree(int n) {
        a.resize(n);
        this->n = n;
        t.resize(4*n+1);
    }

    void build(int v, int tl, int tr) {
        if (tl == tr) {
            t[v] = {a[tl], a[tl]};
        } else {
            int tm = (tl + tr) / 2;
            build( v*2, tl, tm);
            build( v*2+1, tm+1, tr);
            t[v] = merge(t[v*2] , t[v*2+1]); // Fix
        }
    }

    

    void update(int v, int tl, int tr, int pos, long long val) {
    	if (tl == tr and tl == pos)
    		t[v] = {val, val};

    	else if (pos >= tl and pos <= tr) {
    		//cout << "Added " << tl << " , " << tr << endl;
    		int tm = (tl + tr) / 2;
    		update(2*v, tl, tm, pos, val);
    		update(2*v+1, tm+1, tr, pos, val);
            t[v] = merge(t[v*2] , t[v*2+1]);
    	}
    }

    void update(int pos, int val) {
    	update(1, 0, n-1, pos, val);
    }

    pii get(int v, int tl, int tr, int pl, int pr) {
    	//cout << "In range : " << tl << " , " << tr << endl;
    	
    	int tm = (tl + tr)/2;
    	if (tr < pl or pr < tl) 
    		return {LLONG_MIN, LLONG_MAX};
    	if (tl >= pl and tr <= pr) 
    		return t[v];
    	return merge(get(2*v, tl, tm, pl, pr), get(2*v+1, tm+1, tr, pl, pr));
    }
    pii get(int pl, int pr) {
    	return get(1, 0, n-1, pl, pr);
    }
};

struct SegmentTreeGCD {
    vector<int> a;
    vector<int> t;
    int n;

    int merge(int a, int b) {
        return __gcd(a, b);
    }

    SegmentTreeGCD(const vector<long long>& arr) {
        a = arr;
        n = a.size();
        t = vector<int>(4 * n+1);
        build(1, 0, n-1);
    }

    SegmentTreeGCD(int n) {
        a.resize(n);
        this->n = n;
        t.resize(4*n+1);
    }

    void build(int v, int tl, int tr) {
        if (tl == tr) {
            t[v] = a[tl];
        } else {
            int tm = (tl + tr) / 2;
            build( v*2, tl, tm);
            build( v*2+1, tm+1, tr);
            t[v] = merge(t[v*2] , t[v*2+1]); // Fix
        }
    }

    

    void update(int v, int tl, int tr, int pos, long long val) {
    	if (tl == tr and tl == pos)
    		t[v] = val;

    	else if (pos >= tl and pos <= tr) {
    		//cout << "Added " << tl << " , " << tr << endl;
    		int tm = (tl + tr) / 2;
    		update(2*v, tl, tm, pos, val);
    		update(2*v+1, tm+1, tr, pos, val);
            t[v] = merge(t[v*2] , t[v*2+1]);
    	}
    }

    void update(int pos, int val) {
    	update(1, 0, n-1, pos, val);
    }

    int get(int v, int tl, int tr, int pl, int pr) {
    	//cout << "In range : " << tl << " , " << tr << endl;
    	
    	int tm = (tl + tr)/2;
    	if (tr < pl or pr < tl) 
    		return 0;
    	if (tl >= pl and tr <= pr) 
    		return t[v];
    	return merge(get(2*v, tl, tm, pl, pr), get(2*v+1, tm+1, tr, pl, pr));
    }
    int get(int pl, int pr) {
    	return get(1, 0, n-1, pl, pr);
    }
};

void solve() {
    int n , q;
    cin >> n >> q;
    vector<int> arr(n+1);
    for (int i=1; i<=n; i++) cin >> arr[i];

    SegmentTree st(arr);
    vector<int> diff(n+1);

    for (int i=2; i<=n; i++) {
        diff[i] = arr[i] - arr[i-1];
    }
    SegmentTreeGCD stgcd(diff);

    map<int, set<int>> pos;
    map<int, int> lastpos;
    vector<int> last(n+1);
    for (int i=1; i<=n; i++) {
        pos[arr[i]].insert(i);
        if (lastpos.find(arr[i]) == lastpos.end()) {
            last[i] = -1;
        } else {
            last[i] = lastpos[arr[i]];
        }
        lastpos[arr[i]] = i;
    }
    SegmentTree stlast(last);

    while(q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x, y;cin >> x >> y;
            pos[arr[x]].erase(x);
            auto it = pos[arr[x]].lower_bound(x);
            if (it != pos[arr[x]].end()) {
                
                int idx = *it;
                if (it == pos[arr[x]].begin()) {
                    last[idx] = -1;
                } else {
                    last[idx] = *(--it);
                }
                stlast.update(idx, last[idx]);
            }
            
            arr[x] = y;
            st.update(x, y);
            if (x > 1) {
                diff[x] = arr[x] - arr[x-1];
                stgcd.update(x, diff[x]);
            }
            if (x < n) {
                diff[x+1] = arr[x+1] - arr[x];
                stgcd.update(x+1, diff[x+1]);
            }
            pos[arr[x]].insert(x);
            it = pos[arr[x]].lower_bound(x + 1);
            if (it != pos[arr[x]].end()) {
                int idx = *it;
                last[x] = last[idx];
                last[idx] = x;
                stlast.update(idx, last[idx]);
                stlast.update(x, last[x]);
            }else{
                stlast.update(x, -1);
                last[x] = -1;
            }
        }
        else {
            int l, r;
            cin >> l >> r;
            pii max_min = st.get(l, r);
            int maxi = max_min.first;
            int mini = max_min.second;
            if(r - l < 2 or mini == maxi) {
                cout << "YES\n";
                continue;
            }
            if ((maxi - mini) % (r - l) != 0) {
                cout << "NO\n";
                continue;
            }
             
            int d = (maxi - mini) / (r - l);
            int g = stgcd.get(l+1, r);
            if (g % d != 0) {
                cout << "NO\n";
                continue;
            }
            int mx_last = stlast.get(l, r).first;
            if (mx_last >= l) {
                /*for (int i=l; i<=r; i++) {
                    cout << stlast.get(i, i).first << " ";
                }*/
                cout << endl;
                cout << "NO\n";
            } else {
                cout << "YES\n";
            }
        }
    }


    
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    
    return 0;
}

/*
5 8
1 2 3 4 5 6
2 1 2
2 2 5
1 3 6
1 5 8
2 2 5
2 2 6
1 3 10
2 2 6
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

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: 3540kb

input:

2 1
0 1000000000
2 1 2

output:

YES

result:

ok single line: 'YES'

Test #3:

score: -100
Wrong Answer
time: 59ms
memory: 36484kb

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

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

result:

wrong answer 5th lines differ - expected: 'NO', found: ''