当前位置:网站首页>牛客小白月赛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;
}
边栏推荐
- DC-7靶机
- Introduction to the extension implementation of SAP Spartacus checkout process
- Interview questions and salary and welfare of Shanghai byte
- 如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?
- QT console output in GUI applications- Console output in a Qt GUI app?
- 基于ADAU1452的DSP及DAC音频失真分析
- 计算模型 FPS
- Jcmd of JVM command: multifunctional command line
- JVM命令之 jstat:查看JVM统计信息
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
猜你喜欢
一名普通学生的大一总结【不知我等是愚是狂,唯知一路向前奔驰】
如果不知道这4种缓存模式,敢说懂缓存吗?
你不知道的互联网公司招聘黑话大全
【SQL实战】一条SQL统计全国各地疫情分布情况
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
JVM command - jmap: export memory image file & memory usage
Deep clustering: joint optimization of depth representation learning and clustering
Introduction to yarn (one article is enough)
外设驱动库开发笔记43:GPIO模拟SPI驱动
[FPGA tutorial case 14] design and implementation of FIR filter based on vivado core
随机推荐
搞懂fastjson 对泛型的反序列化原理
3531. 哈夫曼树
Reading notes of Clickhouse principle analysis and Application Practice (6)
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
Understand the deserialization principle of fastjson for generics
Add salt and pepper noise or Gaussian noise to the picture
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
980. Different path III DFS
linear regression
那些自损八百的甲方要求
苹果cms V10模板/MXone Pro自适应影视电影网站模板
JVM命令之 jstack:打印JVM中线程快照
改变ui组件原有样式
If you don't know these four caching modes, dare you say you understand caching?
QT console output in GUI applications- Console output in a Qt GUI app?
laravel 使用腾讯云 COS5全教程
The boss always asks me about my progress. Don't you trust me? (what do you think)
从“跑分神器”到数据平台,鲁大师开启演进之路
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
生活中的开销,怎么记账合适