QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600575#5000. Balanced Seesaw ArrayyldRE 1ms5592kbC++204.5kb2024-09-29 17:29:132024-09-29 17:29:14

Judging History

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

  • [2024-09-29 17:29:14]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5592kb
  • [2024-09-29 17:29:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
#define endl '\n'
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int MAXN=1e5+5;
const int inf=1e9;
struct SegmentTree{
    int l,r,sum,mul,lazy1,lazy2;
}tree[MAXN<<2];
int a[MAXN];
void update(int rt)
{
    tree[rt].sum=tree[ls].sum+tree[rs].sum;
    tree[rt].mul=tree[ls].mul+tree[rs].mul;
}
void build(int l,int r,int rt)
{
    tree[rt].lazy1=inf;
    tree[rt].l=l,tree[rt].r=r;
    if(l==r) {tree[rt].sum=a[l],tree[rt].mul=a[l]*l;return;}
    int mid=l+r>>1;
    build(l,mid,ls);
    build(mid+1,r,rs);
    update(rt);
}
void pushdown(int rt)
{
    if(tree[rt].lazy1!=inf)
    {
        tree[ls].lazy1=tree[rs].lazy1=tree[rt].lazy1;
        tree[ls].sum=(tree[ls].r-tree[ls].l+1)*tree[rt].lazy1;
        tree[rs].sum=(tree[rs].r-tree[rs].l+1)*tree[rt].lazy1;
        tree[ls].mul=(tree[ls].l+tree[ls].r)*(tree[ls].r-tree[ls].l+1)/2*tree[rt].lazy1;
        tree[rs].mul=(tree[rs].l+tree[rs].r)*(tree[rs].r-tree[rs].l+1)/2*tree[rt].lazy1;
        tree[ls].lazy2=tree[rs].lazy2=0;
        tree[rt].lazy1=inf;
    }
    if(tree[rt].lazy2)
    {
		tree[ls].lazy2+=tree[rt].lazy2;
		tree[rs].lazy2+=tree[rt].lazy2;
		tree[ls].sum+=(tree[ls].r-tree[ls].l+1)*tree[rt].lazy2;
		tree[rs].sum+=(tree[rs].r-tree[rs].l+1)*tree[rt].lazy2;
		tree[ls].mul+=(tree[ls].l+tree[ls].r)*(tree[ls].r-tree[ls].l+1)/2*tree[rt].lazy2;
		tree[rs].mul+=(tree[rs].l+tree[rs].r)*(tree[rs].r-tree[rs].l+1)/2*tree[rt].lazy2;
		tree[rt].lazy2=0;
    }
}
void modify(int l,int r,int rt,int c)
{
    if(l<=tree[rt].l && tree[rt].r<=r)
    {
        tree[rt].lazy1=c;
        tree[rt].lazy2=0;
        tree[rt].sum=(tree[rt].r-tree[rt].l+1)*c;
        tree[rt].mul=(tree[rt].r-tree[rt].l+1)*(tree[rt].r+tree[rt].l)/2*c;
        return;
    }
    int mid=tree[rt].l+tree[rt].r>>1;
    pushdown(rt);
    if(l<=mid) modify(l,r,ls,c);
    if(r>mid) modify(l,r,rs,c);
    update(rt);
}
void add(int l,int r,int rt,int c)
{
    if(l<=tree[rt].l && tree[rt].r<=r)
    {
        tree[rt].lazy2+=c;
        tree[rt].sum+=(tree[rt].r-tree[rt].l+1)*c;
        tree[rt].mul+=(tree[rt].r-tree[rt].l+1)*(tree[rt].r+tree[rt].l)/2*c;
        return;
    }
    int mid=tree[rt].l+tree[rt].r>>1;
    pushdown(rt);
    if(l<=mid) add(l,r,ls,c);
    if(r>mid) add(l,r,rs,c);
    update(rt);
}
pair<int,int> query(int l,int r,int rt)
{
    if(l<=tree[rt].l && tree[rt].r<=r) return {tree[rt].mul,tree[rt].sum};
    int mid=tree[rt].l+tree[rt].r>>1;
    pushdown(rt);
    pair<int,int> ans={0,0};
    if(l<=mid)
    {
        pair<int,int> temp=query(l,r,ls);
        ans.first+=temp.first,ans.second+=temp.second;
    }
    if(r>mid)
    {
        pair<int,int> temp=query(l,r,rs);
        ans.first+=temp.first,ans.second+=temp.second;
    }
    return ans;
}
int n,q;
void solve()
{
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    build(1,n,1);
	int cnt=0;
    // cerr<<tree[5].l<<' '<<tree[5].r<<' '<<tree[5].sum<<endl;
    while(q--)
    {
		// cnt++;
		// cout<<cnt<<endl;
        int op,l,r;
        cin>>op>>l>>r;
		// cerr<<op<<' '<<l<<' '<<r<<endl;
        if(op==1)
        {
            int x;cin>>x;
            // cerr<<l<<' '<<r<<' '<<x<<endl;
            add(l,r,1,x);
            // cerr<<tree[4].sum<<' '<<tree[5].sum<<' '<<tree[3].sum<<endl;
			
        }
        else if(op==2)
        {
            int x;cin>>x;
            modify(l,r,1,x);
        }
		// cout<<query(l,r,1).second<<endl;
		// for(int i=1;i<=n*2;i++) cout<<tree[i].lazy2<<' ';
		// cout<<endl;
		// cerr<<"\n";
        else
        {
            // cerr<<l<<' '<<r<<endl;
            pair<int,int>temp;
            int m=r-l+1;
            temp=query(l,r,1);
            temp.first-=(l-1)*temp.second;
            // cerr<<temp.first<<' '<<temp.second<<endl;
            if(temp.second==0)
            {
                if(temp.first==0) cout<<"Yes\n";
                else cout<<"No\n";
            }
            if(temp.first%temp.second==0 && temp.first/temp.second<=m && temp.first/temp.second>=1) cout<<"Yes\n";
            else cout<<"No\n";
            // cerr<<"==============\n";
        }
        // cout<<tree[16].sum<<' '<<tree[17].sum<<' '<<tree[9].sum<<' '<<tree[10].sum<<' '<<tree[11].sum<<' ';
		// cout<<tree[24].sum<<' '<<tree[25].sum<<' '<<tree[13].sum<<' '<<tree[14].sum<<' '<<tree[15].sum<<endl;
    }
}
signed main()
{
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);
    cin.tie(0);
    int t=1;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 6
1 2 3
3 1 1
3 1 3
1 1 1 2
3 1 3
2 2 2 0
3 2 3

output:

Yes
No
Yes
Yes

result:

ok 4 lines

Test #2:

score: -100
Runtime Error

input:

100000 451163
-18 609 -793 393 375 313 -55 -892 -446 928 -207 -390 729 -383 27 318 -400 31 -661 202 -978 212 238 -368 351 -613 -23 400 809 1000 -431 -174 -103 886 73 -150 25 820 -689 972 777 794 -36 -231 -966 632 -418 -288 -476 725 -713 -379 896 -19 -883 338 -797 937 -557 -809 -241 -539 704 44 576 -...

output:

No
Yes
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No...

result: