QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577674#9323. Segments and SubsetsAfterlife#TL 1ms3556kbC++201.9kb2024-09-20 13:59:162024-09-20 13:59:17

Judging History

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

  • [2024-09-20 13:59:17]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3556kb
  • [2024-09-20 13:59:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct bit {
    int c[200005];
    int n;
    void init(int _n) {
        n = _n;
        for(int i = 1;i <= n;i++) c[i] = 0;
    }
    void add(int u,int v) {
        while(u <= n) {
            c[u] += v;
            u += (u & -u);
        }
    }
    int qry(int u) {
        int ans= 0;
        while(u) {
            ans += c[u];
            u -= (u & -u);
        }
        return ans;
    }
}b;
int n , x;
typedef pair<int,int> pii;
const int mod = 998244353;
int fpow(int a,int b) {
    int ans = 1;
    while(b) {
        if(b&1) ans = 1LL * ans * a %mod;
        a= 1LL * a * a %mod; b >>= 1;
    }
    return ans;
}
pair<pii,int> val[100005];
void solv() {
    cin >> n >> x;
    vector<int> v;
    map<pii,int> mp;
    for(int i = 1;i <= n;i++) {
        int l , r;cin >> l >> r;
        v.push_back(l) ; v.push_back(r);
        mp[{l,r}]++ ;
    }
    sort(v.begin() , v.end());
    v.erase(unique(v.begin() , v.end()) , v.end()) ;
    int l = v.size() ;
    b.init(v.size()) ;
    int cc = 0;
    for(auto x : mp) val[++cc] = x;
    sort(val + 1 , val + 1  + cc , [&](pair<pii,int> a,pair <pii,int> b) {
        if(a.first.second == b.first.second) return a.first.first > b.first.first ;
        return a.first.second < b.first.second ;
    });
    int ans = 1LL * x * (fpow(2 , n) - 1) % mod;
    for(int i = 1;i <= cc;i++) {
        int id = lower_bound(v.begin() , v.end() , val[i].first.first) - v.begin() + 1;
        int sol = b.qry(n - id + 1) ;
        b.add(n - id + 1 , val[i].second) ;
        ///
        ans = (ans - 1LL * (fpow(2 , val[i].second) - 1) * (val[i].first.second - val[i].first.first) % mod * fpow(2 , n-sol-val[i].second)%mod
        + mod) % mod;
    }
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ;
    int t;cin >> t;
    while(t--) solv() ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Time Limit Exceeded

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:


result: