当前位置:网站首页>Niuke Xiaobai monthly race 52 E. sum logarithms in groups (two points & inclusion and exclusion)

Niuke Xiaobai monthly race 52 E. sum logarithms in groups (two points & inclusion and exclusion)

2022-07-07 06:18:00 Harris-H

Niuke Xiaobai moon race 52 E. Sum logarithms in groups ( Two points & A class )

First save all the numbers in an array , Then use two dimensions vector Save the number of each group .

According to the thought of tolerance and exclusion , For each number, first find all the satisfied numbers by dichotomy, and then subtract the number in your group .

Those in my group are corresponding vector Two points in .

Time complexity : O ( m l o g m ) O(mlogm) O(mlogm)

#include <bits/stdc++.h>
using namespace std;
#define ll long long 

int n, k;

vector<int> ve[1000009], a;
void solved() {
    
    scanf("%d%d", &n, &k);
    int m;
    for(int i = 0; i < n; i ++) {
    
        scanf("%d", &m);
        int x;
        while(m --) {
    
            scanf("%d", &x);
            ve[i].push_back(x);
            a.push_back(x);
        }
        sort(ve[i].begin(), ve[i].end());
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for(int i = 0; i < n; i ++) {
    
        m = ve[i].size();
        for(int j = 0; j < m; j ++) {
    
            int x = ve[i][j], y = k - x;
            ans += 
            (a.end() - upper_bound(a.begin(), a.end(), y - 1)) - 
            (ve[i].end() - upper_bound(ve[i].begin(), ve[i].end(), y - 1));
        }
    }
    ans /= 2;
    cout << ans % 998244353;
}
int main() {
    
    // int ttx; cin >> ttx; while(ttx --) 
        solved();
    return 0;
}
原网站

版权声明
本文为[Harris-H]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070125485028.html