当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Mysql——》Innodb存储引擎的索引

How to write a performance test plan

Recent public ancestor offline practice (tarjan)

三翼鸟两周年:羽翼渐丰,腾飞指日可待

使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏

MySQL中对于索引的理解

Object memory layout

Spark interview questions

Pytorch sharpening chapter | argmax and argmin functions

Indicator trap: seven KPI mistakes that it leaders are prone to make
随机推荐
3DE 资源没东西或不对
Use of vscode
隐藏用户的创建和使用
快乐数[环类问题之快慢指针]
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
内部字段分隔符
EasyExcel 复杂数据导出
flink sql 命令行 连接 yarn
Redis配置与优化
String type conversion BigDecimal, date type
YOLOv5.5 调用本地摄像头
Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
Measurement of reference loop gain and phase margin
2020-ViT ICLR
【JetCache】JetCache的使用方法与步骤
spark analyze命令使用及其作用 map join broadcast join 广播join
【图像分割】2021-SegFormer NeurIPS
Getting started with the lockust series
Training on the device with MIT | 256Kb memory