当前位置:网站首页>牛客小白月赛52 E.分组求对数和(二分&容斥)
牛客小白月赛52 E.分组求对数和(二分&容斥)
2022-07-07 01:25:00 【Harris-H】
牛客小白月赛52 E.分组求对数和(二分&容斥)
先用数组存所有数,然后再用二维vector存每个组的数。
根据容斥思想,对于每个数就先二分找到所有满足的个数然后减掉自己组里的。
自己组里的就是在对应的vector里的二分。
时间复杂度: 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;
}
边栏推荐
- VScode进行代码补全
- mac版php装xdebug环境(m1版)
- Ideas of high concurrency and high traffic seckill scheme
- You don't know the complete collection of recruitment slang of Internet companies
- CTFshow--常用姿势
- Question 102: sequence traversal of binary tree
- Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- Value range of various datetimes in SQL Server 2008
- Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
猜你喜欢

为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾

Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)

Ideas of high concurrency and high traffic seckill scheme

From "running distractor" to data platform, Master Lu started the road of evolution
![[InstallShield] Introduction](/img/df/4522d06510ff918d00659b8358368f.jpg)
[InstallShield] Introduction

基于ADAU1452的DSP及DAC音频失真分析

Red hat install kernel header file

ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略

Jinfo of JVM command: view and modify JVM configuration parameters in real time

如果不知道这4种缓存模式,敢说懂缓存吗?
随机推荐
QT console output in GUI applications- Console output in a Qt GUI app?
[solved] record an error in easyexcel [when reading the XLS file, no error will be reported when reading the whole table, and an error will be reported when reading the specified sheet name]
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
苹果cms V10模板/MXone Pro自适应影视电影网站模板
POI excel export, one of my template methods
A very good JVM interview question article (74 questions and answers)
980. Different path III DFS
Interview skills of software testing
老板总问我进展,是不信任我吗?(你觉得呢)
vim映射大K
Bypass open_ basedir
C. colonne Swapping [tri + Simulation]
关于STC单片机“假死”状态的判别
Change the original style of UI components
Personal imitation SSM framework
DC-7靶机
The solution of a simple algebraic problem
绕过open_basedir
Go language learning notes - Gorm use - native SQL, named parameters, rows, tosql | web framework gin (IX)
A freshman's summary of an ordinary student [I don't know whether we are stupid or crazy, but I know to run forward all the way]