当前位置:网站首页>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;
}
}
边栏推荐
- [combinatorics] recursive equation (special solution form | special solution solving method | special solution example)
- [2. Basics of Delphi grammar] 2 Object Pascal data type
- 鸿蒙第四次培训
- Select 3 fcpx plug-ins. Come and see if you like them
- 1164 Good in C
- Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
- C language string inversion
- 定义一个结构体Fraction,表示分数,用于表示 2/3, 5/6这样的分数
- 基于主机的入侵系统IDS
猜你喜欢

Golang单元测试、Mock测试以及基准测试

Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos

29:第三章:开发通行证服务:12:开发【获得用户账户信息,接口】;(使用VO类包装查到的数据,以符合接口对返回数据的要求)(在多处都会用到的逻辑,在Controller中可以把其抽成一个共用方法)

Take you to API development by hand
![[try to hack] active detection and concealment technology](/img/43/d48f851268fec566ce0cc83bd9557e.png)
[try to hack] active detection and concealment technology

大消费企业怎样做数字化转型?

Life is still confused? Maybe these subscription numbers have the answers you need!

Qt调节Win屏幕亮度和声音大小

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

Simple use of unity pen XR grab
随机推荐
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
设计电商秒杀
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
Swm32 series Tutorial 4 port mapping and serial port application
匯編實例解析--實模式下屏幕顯示
聊聊接口优化的几个方法
Leetcode13. Roman numeral to integer (three solutions)
An example of HP array card troubleshooting
Vs code plug-in korofileheader
A day's work list of an ordinary programmer
Kotlin学习快速入门(7)——扩展的妙用
Open vsftpd port under iptables firewall
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
新库上线 | CnOpenData中国保险机构网点全集数据
Thread pool: the most common and error prone component of business code
一位普通程序员一天工作清单
kubernetes资源对象介绍及常用命令(四)