当前位置:网站首页>Niuke monthly race - logarithmic sum in groups
Niuke monthly race - logarithmic sum in groups
2022-07-01 22:39:00 【A Fusu in the mountains】
Original link
Title Description
The children in Niuniu kindergarten are playing games .
Kindergarten co ownership n Two children , The first i Children have s i s_i si A digital , The first i The number in the hands of a child jj The number is recorded as a i j ( 1 ≤ j ≤ s i ) a_{ij}(1\leq j \leq s_i) aij(1≤j≤si).
Now teacher Niuniu wants to know how many different ways to take a number from two different children to make the sum of the numbers greater than or equal k ?
Because there may be many possible ways , So you just need to tell Niuniu about the numerical simulation of this scheme 998244353 Then the result will be ok ( The answers made up of the same number in the hands of the same child are regarded as different ).
sample input
3 7
4 2 3 1 5
2 4 1
2 8 2
sample output
9
Algorithm
( The principle of tolerance and exclusion + Two points search )
The first thing that comes to mind in this topic is pop search enumeration , Enumerate and search all the sum greater than k The possibility of , But it will obviously time out , It's a square level of complexity
therefore , We can think of , This topic k Already given , So we only ask for each number and k How many numbers are there that have a greater difference between , Then it's not difficult to think of sorting first and then using binary search .
Because each number search cannot contain this group of numbers , We can find two intervals each time , Subtract the number of cells from the number of large interval searches , Finally, accumulation is the answer .
C++ Code
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;const ll mod = 998244353;
int main()
{
ll n,k,cnt;
cin >> n >> k;
vector<ll> v[N],all;
for (int i = 0;i < n;i ++ ) {
int m;
cin >> m;
for (int j = 0;j < m;j ++ ) {
int x;
cin >> x;
v[i].push_back(x);
all.push_back(x);
cnt ++;
}
sort(v[i].begin() , v[i].end());
}
sort(all.begin(),all.end());
ll res = 0,t1 = 0,t2 = 0;
for (int i = 0;i < n;i ++ ) {
for (int j = 0;j < v[i].size();j ++ ) {
t1 = 0,t2 = 0;
t1 = lower_bound(v[i].begin(),v[i].end(),k - v[i][j]) - v[i].begin();
t1 = (ll)v[i].size() - t1;
t2 = lower_bound(all.begin(),all.end(),k - v[i][j]) - all.begin();
t2 = cnt - t2;
//cout << t2 << ' ' << t1 << '\n';
res = (res + t2 - t1) % mod;
}
}
cout << res / 2 << '\n';
return 0;
}
边栏推荐
- YOLOv5.5 调用本地摄像头
- 从零开始学 MySQL —数据库和数据表操作
- [intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
- flink sql 命令行 连接 yarn
- Training on the device with MIT | 256Kb memory
- 搜狗微信APP逆向(二)so层
- 447-哔哩哔哩面经1
- MQ learning notes
- Copy ‘XXXX‘ to effectively final temp variable
- 详解JMM
猜你喜欢

Easyexcel complex data export

Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue

Recent public ancestor (LCA) online practices

The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner

YOLOv5.5 调用本地摄像头

MySQL中对于索引的理解

Kubernetes创建Service访问Pod

MySQL MHA high availability configuration and failover

Rust语言——小小白的入门学习05

Mask wearing detection method based on yolov5
随机推荐
Copy ‘XXXX‘ to effectively final temp variable
Basic knowledge of ngnix
awoo‘s Favorite Problem(优先队列)
MySQL learning notes - SQL optimization of optimization
牛客月赛-分组求对数和
C#/VB.NET 给PDF文档添加文本/图像水印
RestTemplate 远程调用工具类
linux下清理系统缓存并释放内存
Yyds dry goods inventory # solve the real problem of famous enterprises: egg twisting machine
Matlab traverses images, string arrays and other basic operations
Smart micro mm32 multi-channel adc-dma configuration
地图其他篇总目录
LC501. 二叉搜索树中的众数
Icml2022 | interventional contrastive learning based on meta semantic regularization
YOLOv5.5 调用本地摄像头
Communication between browser tab pages
Redis配置与优化
13th Blue Bridge Cup group B national tournament
Medium pen test questions: flip the string, such as ABCD, print out DCBA
【QT小作】封装一个简单的线程管理类