QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694284#9323. Segments and Subsetslytqwq#RE 6ms18516kbC++142.4kb2024-10-31 17:39:142024-10-31 17:39:17

Judging History

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

  • [2024-10-31 17:39:17]
  • 评测
  • 测评结果:RE
  • 用时:6ms
  • 内存:18516kb
  • [2024-10-31 17:39:14]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(i,x,y) for(int i=x;i<=y;++i)
#define go(i,x,y) for(int i=x;i>=y;--i)
#define re return
#define co continue
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ll long long
#define fi first
#define se second
#define gtc getchar
using namespace std;
template<typename T> void out(T *a,int l,int r){fo(i,l,r) cout<<*(a+i)<<' ';puts("");}
inline int read(){
    int x=0,f=1,ch=gtc();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=gtc();
    }
    while(isdigit(ch)){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=gtc();
    }
    re x*f;
}

namespace vectorwyx{

const int N=1e6+5,mod=998244353;
#define modS(x) x=x>=mod?x-mod:x
#define modA(x) x=x<0?x+mod:x
#define add(x,y) x+=y,modS(x)
#define sub(x,y) x-=y,modA(x)
#define pro(x,y) (int)((ll)(x)*(y)%mod)
#define mul(x,y) x=pro(x,y)

int tmp[N],V;
namespace DS{
#define lbit(x) (x&(-x))
int tr[N];//单点加,后缀和
void upd(int x){
    while(x>0) tr[x]++,x-=lbit(x);
}
int ask(int x){
    int ret=0;
    while(x<=V) ret+=tr[x],x+=lbit(x);
    re ret; 
}
void clear(){fo(i,1,V) tr[i]=0;}
}
int l[N],r[N],n,X,od[N],od_[N],pw[N];

void solve(){
    cin>>n>>X;V=0;
    fo(i,1,n) l[i]=read(),r[i]=read()-1,tmp[++V]=l[i],tmp[++V]=r[i];
    sort(tmp+1,tmp+1+V);V=(int)(unique(tmp+1,tmp+1+V)-tmp-1);
    DS::clear();
    fo(i,1,n) l[i]=(int)(lower_bound(tmp+1,tmp+1+V,l[i])-tmp),r[i]=(int)(lower_bound(tmp+1,tmp+1+V,r[i])-tmp);
    fo(i,1,n) od[i]=i;
    auto cmp=[](int x,int y){if(r[x]!=r[y]) re r[x]<r[y];re l[x]>l[y];};
    sort(od+1,od+1+n,cmp);
    fo(i,1,n) assert(l[od[i]]!=l[od[i+1]]||r[od[i]]!=r[od[i+1]]);
    int ans=pro(X,(pw[n]-1));
    fo(i,1,n){
        int L=l[od[i]],R=r[od[i]],k=DS::ask(L);
        // printf("[%d,%d]:%d\n",tmp[L],tmp[R],k);
        sub(ans,pro(tmp[R]-tmp[L]+1,pw[n-k-1]));
        DS::upd(L);
    }
    cout<<ans<<'\n';
    // int m=0;
    // fo(i,1,n-1) if(l[od[i]]!=l[od[i+1]]||r[od[i]]!=r[od[i+1]]) od_[++m]=od[i];
    // od_[++m]=od[n];
    // fo(i,1,m) od[i]=od_[i];
    // cout<<"od:";out(od,1,m);
    // fo(i,1,m){
        
    // }
}

signed main(){
    pw[0]=1;fo(i,1,N-5) pw[i]=pro(2,pw[i-1]);
    int T=read();
    while(T--) solve();
    re 0;
}

}

signed main(){re vectorwyx::main();}


/*
3
2 5
1 4
2 3
3 8
1 3
3 5
5 8
7 10
1 5
2 3
3 4
4 5
5 10
6 9
7 8
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 18516kb

input:

3
2 5
1 4
2 3
3 8
1 3
3 5
5 8
7 10
1 5
2 3
3 4
4 5
5 10
6 9
7 8

output:

10
28
806

result:

ok 3 number(s): "10 28 806"

Test #2:

score: 0
Accepted
time: 6ms
memory: 18296kb

input:

4
1 10
2 5
2 14
2 3
3 6
2 14
2 8
3 5
2 14
2 5
9 14

output:

7
34
32
26

result:

ok 4 number(s): "7 34 32 26"

Test #3:

score: -100
Runtime Error

input:

5
4 11
7 9
10 11
2 5
3 5
4 14
8 9
4 7
2 3
1 3
2 11
2 3
4 8
5 12
11 12
1 2
3 9
4 5
7 8
5 14
4 5
1 3
2 3
6 7
9 11

output:

113
162

result: