当前位置:网站首页>牛客小白月赛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;
}
边栏推荐
- Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
- JVM命令之 jstat:查看JVM统计信息
- 693. 行程排序
- Rk3399 platform development series explanation (interruption) 13.10, workqueue work queue
- Nvisual network visualization
- Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
- PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
- SQL Server 2008 各种DateTime的取值范围
- k8s运行oracle
- JVM监控及诊断工具-命令行篇
猜你喜欢
VScode进行代码补全
ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the
CTFshow--常用姿势
jvm命令之 jcmd:多功能命令行
PTA ladder game exercise set l2-004 search tree judgment
[SQL practice] a SQL statistics of epidemic distribution across the country
On the discrimination of "fake death" state of STC single chip microcomputer
测试开发基础,教你做一个完整功能的Web平台之环境准备
How to improve website weight
Interview questions and salary and welfare of Shanghai byte
随机推荐
搞懂fastjson 对泛型的反序列化原理
当我们谈论不可变基础设施时,我们在谈论什么
Sequential storage of stacks
Financial risk control practice - decision tree rule mining template
蚂蚁庄园安全头盔 7.8蚂蚁庄园答案
CMD permanently delete specified folders and files
From "running distractor" to data platform, Master Lu started the road of evolution
高并发大流量秒杀方案思路
测试开发基础,教你做一个完整功能的Web平台之环境准备
A very good JVM interview question article (74 questions and answers)
Oracle迁移中关于大容量表使用数据泵(expdp、impdp)导出导入容易出现的问题和注意事项
980. Different path III DFS
Jstat pour la commande JVM: voir les statistiques JVM
云加速,帮助您有效解决攻击问题!
每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
cf:C. Column Swapping【排序 + 模擬】
JVM monitoring and diagnostic tools - command line
从“跑分神器”到数据平台,鲁大师开启演进之路
Jinfo of JVM command: view and modify JVM configuration parameters in real time
Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?