当前位置:网站首页>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;
}
}
边栏推荐
- Host based intrusion system IDS
- Atom QT 16_ audiorecorder
- 企业级自定义表单引擎解决方案(十一)--表单规则引擎1
- Talk about several methods of interface optimization
- Applet setting multi account debugging
- When absolutely positioned, the element is horizontally and vertically centered
- 绝对定位时元素水平垂直居中
- [combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
- vs code 插件 koroFileHeader
- 聊聊接口优化的几个方法
猜你喜欢

vs2013已阻止安装程序,需安装IE10

聊聊接口优化的几个方法

大变局!全国房价,跌破万元大关

Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires

Analysis of variance summary

The most complete postman interface test tutorial in the whole network, API interface test

Great changes! National housing prices fell below the 10000 yuan mark

Build your own website (23)

Applet setting multi account debugging

One brush 149 force deduction hot question-10 regular expression matching (H)
随机推荐
Atom QT 16_ audiorecorder
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
Talk about several methods of interface optimization
SVN如何查看修改的文件记录
The largest matrix (H) in a brush 143 monotone stack 84 histogram
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
How to train mask r-cnn model with your own data
Qt调节Win屏幕亮度和声音大小
A day's work list of an ordinary programmer
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
線程池:業務代碼最常用也最容易犯錯的組件
图之深度优先搜索
Installation and configuration of network hard disk NFS
Redis: operation commands for list type data
C语言字符串反转
What is your income level in the country?
Great changes! National housing prices fell below the 10000 yuan mark
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“