QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134003#4940. Token Distancedzy521WA 24ms17176kbC++234.7kb2023-08-02 20:20:412023-08-02 20:20:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 20:20:41]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:17176kb
  • [2023-08-02 20:20:41]
  • 提交

answer

#define _CRT_SEstartE_NO_DEPRECATE
#pragma warning(disable : 4996)
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
#define ACcode ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 7;
const ll maxm = 1e7 + 5e6 + 7;
constexpr ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int Prime = 100007;
const double eps = 1e-5;
const double pi = acos(-1.0);
using namespace std;

ll a[maxn][2];
struct node
{
    ll mx, mi, sum;
    friend node operator+(const node &a, const node &b)
    {
        node now;
        now.mx = max(a.mx, b.mx);
        now.mi = min(a.mi, b.mi);
        now.sum = a.sum + b.sum;
        return now;
    }
} tree[maxn << 2];
void build(int k, int l, int r)
{
    if (l == r)
    {
        tree[k] = {a[l][0], a[l][0], a[l][0]};
        return;
    }
    int mid = l + r >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
    tree[k] = tree[k << 1] + tree[k << 1 | 1];
}
void change(int k, int l, int r, int pos, ll x)
{
    if (l == r)
    {
        tree[k] = {x, x, x};
        return;
    }
    int mid = l + r >> 1;
    if (pos <= mid)
        change(k << 1, l, mid, pos, x);
    else
        change(k << 1 | 1, mid + 1, r, pos, x);
    tree[k] = tree[k << 1] + tree[k << 1 | 1];
}
node query(int k, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr)
        return tree[k];
    int mid = l + r >> 1;
    if (qr <= mid)
        return query(k << 1, l, mid, ql, qr);
    else if (ql > mid)
        return query(k << 1 | 1, mid + 1, r, ql, qr);
    else
        return query(k << 1, l, mid, ql, qr) + query(k << 1 | 1, mid + 1, r, ql, qr);
}
struct SEG
{
    ll sum[maxn << 2];
    void build(int k, int l, int r)
    {
        if (l == r)
        {
            sum[k] = a[l][1];
            return;
        }
        int mid = l + r >> 1;
        build(k << 1, l, mid);
        build(k << 1 | 1, mid + 1, r);
        sum[k] = (sum[k << 1] + sum[k << 1 | 1]) % mod;
    }
    void change(int k, int l, int r, int pos, ll x)
    {
        if (l == r)
        {
            sum[k] = x;
            return;
        }
        int mid = l + r >> 1;
        if (pos <= mid)
            change(k << 1, l, mid, pos, x);
        else
            change(k << 1 | 1, mid + 1, r, pos, x);
        sum[k] = (sum[k << 1] + sum[k << 1 | 1]) % mod;
    }
    ll query(int k, int l, int r, int ql, int qr)
    {
        if (l >= ql && r <= qr)
            return sum[k];
        int mid = l + r >> 1;
        if (qr <= mid)
            return query(k << 1, l, mid, ql, qr);
        else if (ql > mid)
            return query(k << 1 | 1, mid + 1, r, ql, qr);
        else
            return (query(k << 1, l, mid, ql, qr) + query(k << 1 | 1, mid + 1, r, ql, qr)) % mod;
    }
} seg;
ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod, b >>= 1;
    }
    return ans;
}
void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i][0], a[i][1] = qpow(2, a[i][0]);
    build(1, 1, n);
    seg.build(1, 1, n);
    for (int i = 1; i <= m; i++)
    {
        ll ope, l, r;
        cin >> ope >> l >> r;
        if (ope == 1)
        {
            change(1, 1, n, l, r);
            seg.change(1, 1, n, l, qpow(2, r));
        }
        else
        {
            auto [mx, mi, sum] = query(1, 1, n, l, r);
            ll realsum = seg.query(1, 1, n, l, r);
            int len = r - l + 1;
            ll d1 = 2 * (sum - len * mi), d2 = len * (len - 1);
            if (d1 % d2 != 0)
            {
                cout << "NO" << '\n';
                continue;
            }
            ll d = d1 / d2;
            ll q = qpow(2, d), a1 = qpow(2, mi);
            if (q == 1)
            {
                cout << (sum * 2 % mod == realsum % mod ? "YES" : "NO") << '\n';
                continue;
            }
            ll nowsum = a1 * ((1 - qpow(q, len) + mod) % mod) % mod * qpow((1 - q + mod) % mod, mod - 2) % mod;
            cout << (nowsum == realsum ? "YES" : "NO") << '\n';
        }
    }
}

signed main()
{
    ACcode;
    // freopen("house.in", "r", stdin);
    // freopen("house.out", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5672kb

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

input:

2 1
0 1000000000
2 1 2

output:

YES

result:

ok single line: 'YES'

Test #3:

score: -100
Wrong Answer
time: 24ms
memory: 17176kb

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

result:

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