QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#877816#9986. Shioriucup-team6274RE 1920ms9828kbC++204.7kb2025-02-01 09:29:352025-02-01 09:29:36

Judging History

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

  • [2025-02-01 09:29:36]
  • 评测
  • 测评结果:RE
  • 用时:1920ms
  • 内存:9828kb
  • [2025-02-01 09:29:35]
  • 提交

answer

#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1e18)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
int mod=998244353;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
    int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}

int n,q,a[500010];

const int B=500,N=5e5;

int bel[N+5],L[N/B+5],R[N/B+5],tag[N/B+5],cov[N/B+5],sum[N/B+5];

bitset<N*4+5> occ[N/B+5];

void rebuild(int b){
    if(~cov[b]){
        for(int i=L[b];i<=R[b];i++){
            a[i]=cov[b];
        }
        cov[b]=-1;
    }
    occ[b].reset();
    for(int i=L[b];i<=R[b];i++){
        if(a[i]>N*2){
            exit(0);
        }
        occ[b][a[i]]=1;
    }
    sum[b]=accumulate(a+L[b],a+R[b]+1,0ll)+tag[b]*(R[b]-L[b]+1);
}
void cover(int l,int r,int x){
    int bl=bel[l],br=bel[r];
    if(bl==br){
        for(int i=l;i<=r;i++)a[i]=x-tag[bl];
        return rebuild(bl);
    }
    rebuild(bl);
    rebuild(br);

    for(int i=l;i<=R[bl];i++){
        a[i]=x-tag[bl];
    }
    for(int i=L[br];i<=r;i++){
        a[i]=x-tag[br];
    }
    for(int i=bl+1;i<br;i++){
        cov[i]=x,tag[i]=0;
        sum[i]=x*(R[i]-L[i]+1);
    }

    rebuild(bl);rebuild(br);
}
void add(int l,int r,int x){
    int bl=bel[l],br=bel[r];
    if(bl==br){
        rebuild(bl);
        for(int i=l;i<=r;i++)a[i]+=x;
        return rebuild(bl);
    }

    rebuild(bl);
    rebuild(br);
    for(int i=l;i<=R[bl];i++)a[i]+=x;
    for(int i=L[br];i<=r;i++)a[i]+=x;
    for(int i=bl+1;i<br;i++){
        tag[i]+=x,sum[i]+=(R[i]-L[i]+1)*x;
    }
    rebuild(bl);
    rebuild(br);
}
int qry(int l,int r){
    int bl=bel[l],br=bel[r],ans=0;
    if(bl==br){
        for(int i=l;i<=r;i++){
            ans+=(~cov[bl]?cov[bl]:a[i])+tag[bl];
        }
    }else{
        for(int i=l;i<=R[bl];i++){
            ans+=(~cov[bl]?cov[bl]:a[i])+tag[bl];
        }
        for(int i=L[br];i<=r;i++){
            ans+=(~cov[br]?cov[br]:a[i])+tag[br];
        }
        for(int i=bl+1;i<br;i++){
            ans+=sum[i];
        }
    }
    return ans;
}
bool occur(int l,int r,int x){
    int bl=bel[l],br=bel[r];
    if(bl==br){
        if(~cov[bl]){
            return cov[bl]+tag[bl]==x;
        }
        for(int i=l;i<=r;i++){
            if(a[i]+tag[bl]==x)return 1;
        }
        return 0;
    }
    if(~cov[bl]){
        if(cov[bl]+tag[bl]==x)return 1;
    }else{
        for(int i=l;i<=R[bl];i++){
            if(a[i]+tag[bl]==x)return 1;
        }
    }

    if(~cov[br]){
        if(cov[br]+tag[br]==x)return 1;
    }else{
        for(int i=L[br];i<=r;i++){
            if(a[i]+tag[br]==x)return 1;
        }
    }

    for(int i=bl+1;i<br;i++){
        if(~cov[i]){
            if(cov[i]+tag[i]==x)return 1;
        }else{
            if(tag[i]<=x&&occ[i][x-tag[i]])return 1;
        }
    }
    return 0;
}

void work(){
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        bel[i]=(i-1)/B+1;
    }
    for(int i=1;i<=bel[n];i++){
        L[i]=(i-1)*B+1;
        R[i]=i*B;
        cov[i]=-1;
    }
    R[bel[n]]=n;

    for(int i=1;i<=bel[n];i++){
        rebuild(i);
    }

    for(int i=1,op,l,r,x;i<=q;i++){
        cin>>op>>l>>r;
        if(op==1){
            cin>>x;
            cover(l,r,x);
        }else if(op==2){
            int mex=0;
            while(occur(l,r,mex)){
                ++mex;
            }
            add(l,r,mex);
        }else{
            cout<<qry(l,r)<<'\n';
        }
    }
    
}
bool Med;
signed main(){
    ios::sync_with_stdio(0),
    cin.tie(0),cout.tie(0);
    int T=1;while(T--)work();
    // cerr<<"Time: "<<clock()<<" ms;\n";
    // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/

詳細信息

Test #1:

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

input:

5 8
0 7 2 1 0
1 2 4 0
2 1 3
2 3 4
3 1 3
1 2 3 4
3 1 4
2 1 5
3 2 5

output:

5
11
22

result:

ok 3 number(s): "5 11 22"

Test #2:

score: 0
Accepted
time: 0ms
memory: 7908kb

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: 0
Accepted
time: 1920ms
memory: 7912kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
3 2 9
2 4 10
2 2 7
2 7 9
3 1 1
3 5 8
1 5 10 0
3 1 9
3 5 9
2 2 4
1 2 4 0
2 5 6
3 8 8
1 4 6 0
1 6 6 0
2 4 10
3 1 9
3 5 7
1 4 10 0
3 6 9
3 2 6
2 1 8
1 5 9 0
3 7 8
3 4 8
2 4 8
2 5 8
2 1 9
2 3 8
1 5 10 0
2 4 8
3 1 6
2 1 4
2 3 7
3 4 10
1 4 6 0
1 1 6 0
2 3 7
1 1 1 0
2 1 10
1 5...

output:

0
0
10
7
0
0
6
3
0
0
0
1
25
12
10
0
0
0
0
17
23
1
20
2
11
27
26
2
18
2
2
0
0
0
2
4
1
0
0
0
7
2
0
4
32
15
7
11
0
4
5
2
8
5
1
6
0
7
0
7
6
3
2
5
0
0
0
7
14
2
5
0
2
0
0
6
12
6
0
2
3
0
0
1
16
12
1
1
12
0
3
4
4
10
3
16
0
17
2
4
0
0
16
8
2
8
18
23
2
24
4
12
7
4
14
5
0
2
8
4
16
10
6
4
21
15
1
3
3
0
2
5
0
2
...

result:

ok 166844 numbers

Test #4:

score: 0
Accepted
time: 1920ms
memory: 7912kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
2 9 10
1 1 3 0
1 1 2 0
2 2 4
3 8 8
2 6 6
2 5 6
3 2 9
2 4 4
1 2 6 0
2 5 7
1 2 10 0
3 1 4
3 1 10
1 6 7 0
1 1 1 0
1 3 9 0
3 4 7
3 2 8
1 6 9 0
1 3 5 0
1 5 10 0
3 2 5
1 2 9 0
1 7 8 0
2 5 10
3 2 3
2 5 5
2 8 9
3 1 6
2 2 6
2 3 6
3 4 5
1 1 6 0
1 1 5 0
3 3 8
3 2 9
3 3 7
1 2 10 0
...

output:

0
9
0
0
0
0
0
0
2
5
2
3
1
0
5
7
1
0
1
3
20
1
23
13
7
14
6
19
0
2
1
2
1
1
0
1
2
2
3
1
0
0
12
28
20
0
0
0
0
0
1
0
1
1
0
2
21
6
9
2
5
10
0
0
0
1
2
1
0
0
0
1
1
0
3
0
2
0
2
0
2
2
2
0
8
3
2
1
0
2
12
4
2
0
0
6
0
9
3
15
0
0
6
0
14
11
6
0
5
4
4
26
11
8
7
7
10
0
4
6
2
4
4
6
4
7
0
3
6
4
20
3
17
14
18
14
9
13
8...

result:

ok 166636 numbers

Test #5:

score: -100
Runtime Error

input:

500000 500000
472024 143520 268267 155743 162119 212911 326774 283734 445407 353394 432929 138490 36366 247037 157063 203731 162782 54322 321700 39379 6459 358816 32001 245189 167252 460348 113630 85323 283872 285182 191285 487821 395892 328168 467455 469639 234067 325083 145477 450046 16029 142429 ...

output:


result: