QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134008#4940. Token Distancedzy521WA 26ms17376kbC++234.8kb2023-08-02 20:25:282023-08-02 20:25:32

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:25:32]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:17376kb
  • [2023-08-02 20:25:28]
  • 提交

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;
#define int ll
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 % mod;
            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;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7540kb

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

input:

2 1
0 1000000000
2 1 2

output:

YES

result:

ok single line: 'YES'

Test #3:

score: 0
Accepted
time: 23ms
memory: 14804kb

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: 26ms
memory: 17376kb

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: 25ms
memory: 14880kb

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: -100
Wrong Answer
time: 26ms
memory: 17224kb

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:

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

result:

wrong answer 1st lines differ - expected: 'YES', found: 'NO'