QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473737#6427. Just Another Game of StonesRainingLoveRE 0ms0kbC++235.0kb2024-07-12 13:44:382024-07-12 13:44:38

Judging History

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

  • [2024-07-12 13:44:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-12 13:44:38]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,q,a[maxn],op,l,r,x;

char buf[1 << 20], *_now = buf, *_end = buf;
//buf是缓冲数组,就是读入的一串数据存放的地方;_now是字符指针,指向当前想取的那个字符;_end也是字符指针,指向这一串字符的最后一个。
inline char getcharA() {
	if (_now == _end) {//如果这一串数据处理完了
		_end = _now = buf;
		_end += fread(buf, 1, 1 << 20, stdin);//那就再读一串,注意指针要回归原位
		if(_now == _end) {//如果没有读进来,就说明没有数据了
			return EOF;
		}
	}
	return *_now++;
}

inline int read() {
    int x=0,f=1;
    char ch=getcharA();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getcharA();}
    while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+(ch^48);ch=getcharA();}
    return x*f;
}

const int maxm=500+5;
int bel[maxn],st[maxm],ed[maxm];
int Max[maxm];
vector<int>qwq[maxm],Xor[maxm],sum[30][maxm];
int qp[30];
int main() {

    ios::sync_with_stdio(0);
    // cin.tie(0),cout.tie(0);

    n=read(),q=read();
    for(int i=1;i<=n;++i) a[i]=read();
    qp[0]=1;
    for(int i=1;i<=29;++i) qp[i]=(qp[i-1]<<1);
    int block=sqrt(n);
    for(int i=1;i<=(n-1)/block+1;++i) {
        st[i]=(i-1)*block+1;
        ed[i]=min(i*block,n);
        for(int j=st[i];j<=ed[i];++j) {
            bel[j]=i;
            qwq[i].push_back(a[j]);
            Xor[i].push_back(0);
            for(int k=0;k<=29;++k) sum[k][i].push_back(0);
        }
        sort(qwq[i].begin(),qwq[i].end());
        for(int j=0;j<qwq[i].size();++j) {
            if(j==0) {
                Xor[i][j]=qwq[i][j];
                for(int k=0;k<=29;++k) sum[k][i][j]=((qwq[i][j]&qp[k])!=0);
            }
            else {
                Xor[i][j]=(Xor[i][j-1]^qwq[i][j]);
                for(int k=0;k<=29;++k) sum[k][i][j]=((qwq[i][j]&qp[k])!=0)+sum[k][i][j-1];
            }
        }
    }
    while(q--) {
        op=read(),l=read(),r=read(),x=read();
        if(op==1) {
            int s=bel[l]+1,t=bel[r]-1;
            for(int i=s;i<=t;++i) Max[i]=max(Max[i],x);
            for(int i=st[s-1];i<=ed[s-1];++i) {
                a[i]=max(a[i],Max[s-1]);
                if(l<=i&&i<=r) a[i]=max(a[i],x);
                qwq[s-1][i-st[s-1]]=a[i];
            }
            Max[s-1]=0;
            sort(qwq[s-1].begin(),qwq[s-1].end());
            for(int i=0;i<qwq[s-1].size();++i) {
                if(i==0) {
                    Xor[s-1][i]=qwq[s-1][i];
                    for(int k=0;k<=29;++k) sum[k][s-1][i]=((qwq[s-1][i]&qp[k])!=0);
                }
                else {
                    Xor[s-1][i]=(Xor[s-1][i-1]^qwq[s-1][i]);
                    for(int k=0;k<=29;++k) sum[k][s-1][i]=((qwq[s-1][i]&qp[k])!=0)+sum[k][s-1][i-1];
                }
            }
            if(bel[l]!=bel[r]) {
                for(int i=st[t+1];i<=ed[t+1];++i) {
                    a[i]=max(a[i],Max[t+1]);
                    if(l<=i&&i<=r) a[i]=max(a[i],x);
                    qwq[t+1][i-st[t+1]]=a[i];
                }
                Max[t+1]=0;
                sort(qwq[t+1].begin(),qwq[t+1].end());
                for(int i=0;i<qwq[t+1].size();++i) {
                    if(i==0) {
                        Xor[t+1][i]=qwq[t+1][i];
                        for(int k=0;k<=29;++k) sum[k][t+1][i]=((qwq[t+1][i]&qp[k])!=0);
                    }
                    else {
                        Xor[t+1][i]=(Xor[t+1][i-1]^qwq[t+1][i]);
                        for(int k=0;k<=29;++k) sum[k][t+1][i]=((qwq[t+1][i]&qp[k])!=0)+sum[k][t+1][i-1];
                    }
                }
            }
        }
        else {
            int s=bel[l]+1,t=bel[r]-1;
            int tmp=0;
            for(int i=s;i<=t;++i) {
                int p=upper_bound(qwq[i].begin(),qwq[i].end(),Max[i])-qwq[i].begin();
                int len=qwq[i].size();
                tmp^=(Xor[i][len-1]^Xor[i][p-1]);
                if(p&1) tmp^=Max[i];
            }
            for(int i=l;i<=min(r,ed[s-1]);++i) tmp^=max(a[i],Max[s-1]);
            if(bel[l]!=bel[r]) {
                for(int i=st[t+1];i<=r;++i) tmp^=max(a[i],Max[t+1]);
            }
            tmp^=x;
            if(tmp==0) puts("0");
            else {
                int js=-1;
                int ans=0;
                if((tmp^x)<x) ans++;
                while(tmp) js++,tmp>>=1;
                for(int i=l;i<=min(r,ed[s-1]);++i) if((max(a[i],Max[s-1])&(1<<js))) ans++;
                if(bel[l]!=bel[r]) {
                    for(int i=st[t+1];i<=r;++i) if((max(a[i],Max[t+1])&(1<<js))) ans++;
                }
                for(int i=s;i<=t;++i) {
                    int p=upper_bound(qwq[i].begin(),qwq[i].end(),Max[i])-qwq[i].begin();
                    int len=qwq[i].size();
                    if((Max[i]&(1<<js))) ans+=p;
                    ans+=sum[js][i][len-1]-sum[js][i][p-1];
                }
                printf("%d\n",ans);
            }
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5 4
1 2 1 4 1
2 1 3 1
1 2 4 3
2 2 4 4
2 1 4 4

output:


result: