QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528214#4940. Token DistanceCaptainflyWA 0ms3688kbC++203.4kb2024-08-23 11:39:592024-08-23 11:39:59

Judging History

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

  • [2024-08-23 11:39:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3688kb
  • [2024-08-23 11:39:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
using i128 = __int128;
#define mp make_pair
#define ull unsigned long long
#define all(x) x.begin(), x.end()
//__builtin_count()
typedef array<int,2> pr;
const unsigned int mask =  (chrono::steady_clock::now().time_since_epoch().count());
inline int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}//gcd(a,b)=gcd(a,b-a)(b>a);
inline int lcm(int a, int b){return a / gcd(a, b) * b;}//lcm(n,m)=n*m/gcd(n,m)
const ll mod = 1e18+9;
const int inv2 = (mod+1)/2;
#define lson rt<<1
#define rson rt<<1|1
int addmod(int &x, int y) {x = (x + y >= mod ? x + y - mod : x + y);return 1;}
ll qpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll inv(int x){return qpow(x,mod-2);}
inline void read(__int128 &x)
{
    char c; while(!((c=getchar())>='0'&&c<='9'));
    x=c-'0';
    while((c=getchar())>='0'&&c<='9') (x*=10)+=c-'0';
}
int o[200010],on;
inline void output(__int128 x)
{
    on=0;
    while(x) o[++on]=x%10,x/=10;
    for(int i=on;i>=1;i--) cout<<o[i];
}
#define maxn 200010
struct Info{
    int mx,mn;
    ll s1,s2;
    Info()=default;
    Info(int x)
    {
        mn=mx=s1=x;
        s2=1ll*x*x;
    }
};
Info operator +(Info a,Info b)
{
    Info c;
    c.mn=min(a.mn,b.mn);
    c.mx=max(a.mx,b.mx);
    c.s1=(a.s1+b.s1)%mod;
    c.s2=(a.s2+b.s2)%mod;
    return c;
}
struct node {
    int l,r;
    Info info;
}seg[maxn<<2];
int n,m,w[maxn];
void pushup(int rt)
{
    seg[rt].info=seg[lson].info+seg[rson].info;
}
void build(int rt,int l,int r)
{
    seg[rt]={l,r,Info(w[l])};
    if(l==r)
    {
        return ;
    }
    int mid = (l+r)>>1;
    build(lson,l,mid);
    build(rson,mid+1,r);
    pushup(rt);
}
void modify(int rt,int pos,int val)
{
    if(seg[rt].l==seg[rt].r)
    {
        seg[rt].info=Info(val);
        return ;
    }
    int mid = (seg[rt].l+seg[rt].r)>>1;
    if(pos<=mid)
    {
        modify(lson,pos,val);
    }
    else modify(rson,pos,val);
    pushup(rt);
}
Info query(int rt,int l,int r)
{
    if(l<=seg[rt].l&&seg[rt].r<=r)
    {
        return seg[rt].info;
    }
    int mid = (seg[rt].l+seg[rt].r)>>1;
    if(r<=mid) return query(lson,l,r);;
    if(l>mid) return query(rson,l,r);
    return query(lson,l,r)+query(rson,l,r);
}
ll sum(int n,int s,int d)
{
    ll ans=i128(6)*n*s*s%mod;
    (ans+=i128(6)*d*(n+1)*n*s%mod)%=mod;
    (ans+=i128(1)*n*(n+1)*(2*n+1)%mod*d*d)%=mod;
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];
    }
    build(1,1,n);
    while(m--)
    {
        int op,x,y;
        cin>>op>>x>>y;
        if(op==1)
        {
            modify(1,x,y);
        }
        else 
        {
            auto [mn,mx,s1,s2]=query(1,x,y);
            int t=y-x;
            if((mx-mn)%t)
            {
                cout<<"NO"<<'\n';
                continue;
            }
            int d=(mx-mn)/t;
            ll tar1=1ll*(mn+mx)*(t+1)/2%mod;
            ll tar2=(sum(y-x+1,mn-d,d)%mod+mod)%mod;
            if(pair(s1,6ll*s2%mod)==pair(tar1,tar2))
            {
                cout<<"YES"<<'\n';
            }
            else 
            {
                cout<<"NO"<<'\n';
            }
        }
    }
}

詳細信息

Test #1:

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

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

input:

2 1
0 1000000000
2 1 2

output:

NO

result:

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