当前位置:网站首页>Y is always discrete and can't understand, how to solve it? Answer: read it several times
Y is always discrete and can't understand, how to solve it? Answer: read it several times
2022-07-03 17:19:00 【Liuyun maple】
y Always discrete and can't understand , How to solve ? Answer: read it several times
I saw y Total discrete and , It was supposed to collapse , But the barrage track : Look at it several times. . Do not deceive me , Here's a record , Also wrote more specific notes .
Challenge time , Suddenly I found that my hand speed increased a lot , The program is simple and happy
Interval and
Suppose there is an infinite number axis , The number on each coordinate on the number axis is 00.
Now? , Let's start with nn operations , Each operation will a certain position xx Add... To the number on cc.
Next , Conduct mm Time to ask , Each query contains two integers ll and rr, You need to find the interval [l,r][l,r] The sum of all numbers between .
Input format
The first line contains two integers nn and mm.
Next nn That's ok , Each line contains two integers xx and cc.
Next mm That's ok , Each line contains two integers ll and rr.
Output format
common mm That's ok , Each line outputs a number in the interval and .
Data range
−109≤x≤109−109≤x≤109,
1≤n,m≤1051≤n,m≤105,
−109≤l≤r≤109−109≤l≤r≤109,
−10000≤c≤10000
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> pll;
vector<pll> adds,query;
vector<int> alls; // Store all the coordinates that need to be operated in
const int N = 300010;
int a[N],s[N];
// In fact, the discretization of large coordinates , Is the element value of the array, that is alls[i] It represents the value of the big target , Using discretization, the large scale can be corresponding to the small scale i, We use small coordinates to process . I think I've seen it several times , That's pretty clear .
// Use dichotomy to determine the number of small marks corresponding to the original big mark
int find(int x){
int l = 0, r = alls.size();
while(l < r){
int mid = l + r >> 1;
if(alls[mid] >= x) r = mid;
else l = mid + 1;
}
return r + 1;
}
int main(){
int n,m; cin >> n >> m;
for(int i = 0; i < n; i++) {
int x, c;
cin >> x >> c;
alls.push_back(x);
adds.push_back({
x,c});
}
for(int i = 0; i < m; i++){
int l,r;
cin >> l >> r;
query.push_back({
l,r});
alls.push_back(l);
alls.push_back(r);
}
sort(alls.begin(),alls.end());
alls.erase(unique(alls.begin(),alls.end()),alls.end()); // duplicate removal
for(auto item: adds){
// The first step in implementing the requirements of the topic
int x = find(item.first); // Find the small coordinate corresponding to the large coordinate
a[x] += item.second;
}
// Prefixes and preprocessing
for(int i = 1; i <= alls.size(); i++) s[i] = s[i-1] + a[i];
// Perform the second step of the topic
for(auto item : query){
int l = find(item.first), r = find(item.second);
cout << s[r] - s[l-1] << endl;
}
}
边栏推荐
- Where is the database account used when running SQL tasks in data warehouse tasks configured
- Comparison of kotlin collaboration + retro build network request schemes
- 定义一个结构体Fraction,表示分数,用于表示 2/3, 5/6这样的分数
- Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard
- Test your trained model
- The largest matrix (H) in a brush 143 monotone stack 84 histogram
- New library online | cnopendata complete data of Chinese insurance institution outlets
- New library online | cnopendata China bird watching record data
- Kubernetes resource object introduction and common commands (4)
- 国内如何购买Google Colab会员
猜你喜欢

vs2013已阻止安装程序,需安装IE10
![[UE4] brush Arctic pack high quality Arctic terrain pack](/img/e7/bc86bd8450b0b2bdec8980a2aa1a10.jpg)
[UE4] brush Arctic pack high quality Arctic terrain pack
![29: Chapter 3: develop Passport Service: 12: develop [obtain user account information, interface]; (use VO class to package the found data to meet the requirements of the interface for the returned da](/img/1c/c655c8232de1c56203873dcf171f45.png)
29: Chapter 3: develop Passport Service: 12: develop [obtain user account information, interface]; (use VO class to package the found data to meet the requirements of the interface for the returned da

Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard
![[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.](/img/a0/4fc0e0741aad2885873e60f2af3387.jpg)
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.

kubernetes资源对象介绍及常用命令(三)

How to train mask r-cnn model with your own data

Kubernetes resource object introduction and common commands (4)

1164 Good in C

Bcvp developer community 2022 exclusive peripheral first bullet
随机推荐
When absolutely positioned, the element is horizontally and vertically centered
The most complete postman interface test tutorial in the whole network, API interface test
绝对定位时元素水平垂直居中
Golang单元测试、Mock测试以及基准测试
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
Open vsftpd port under iptables firewall
SVN如何查看修改的文件记录
Squid 服务启动脚本
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
Unity notes unityxr simple to use
How to allow remote connection to MySQL server on Linux system?
鸿蒙第四次培训
How do large consumer enterprises make digital transformation?
Design e-commerce spike
图之深度优先搜索
PS screen printing brush 131, many illustrators have followed suit
New library online | cnopendata China bird watching record data
RDS数据库的监测页面在哪看?
Rsync远程同步
TensorBoard快速入门(Pytorch使用TensorBoard)