import java.util.*;
import java.util.Collections;
public class Main {
static class Pair {
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
int a;
int b;
}
static int N = 300_007;
static int[] a = new int[N], s = new int[N];
static List<Integer> alls = new ArrayList<>();
static List<Pair> add = new ArrayList<>(), query = new ArrayList<>();
private static int left_search(List<Integer> alls, int x) {
int left = 0, right = alls.size() - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (alls.get(mid) < x) left = mid + 1;
else right = mid - 1;
}
return left;
}
private static int unique(List<Integer> alls) {
int i = 0;
for (int j = 0; j < alls.size(); j++) {
int x = alls.get(j);
if (j == 0 || x != alls.get(j-1)) {
alls.set(i++, x);
}
}
return i;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt();
for (int i = 0; i < n; i++) {
int x = sc.nextInt(), c = sc.nextInt();
add.add(new Pair(x, c));
alls.add(x);
}
for (int i = 0; i < m; i++) {
int l = sc.nextInt(), r = sc.nextInt();
query.add(new Pair(l, r));
alls.add(l);
alls.add(r);
}
// 排序 + 去重
Collections.sort(alls);
alls = alls.subList(0, unique(alls));
// 修改
for (var p: add) {
int idx = left_search(alls, p.a) + 1;
a[idx] += p.b;
}
// 前缀和
for (int i = 1; i <= alls.size(); i++) {
s[i] = s[i-1] + a[i];
}
// 查询
for (var p: query) {
int l = p.a, r = p.b;
l = left_search(alls, l) + 1;
r = left_search(alls, r) + 1;
System.out.println(s[r] - s[l-1]);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
历届蓝桥杯大量比赛真题+算法+提升课程 (248个子文件)
5165. CCC单词搜索.cpp 3KB
1086. 恨7不成妻.cpp 3KB
5170. 二进制.cpp 2KB
2376. 统计特殊整数.cpp 2KB
858. Prim算法求最小生成树.cpp 2KB
3302. 表达式求值.cpp 2KB
5017. 垦田计划.cpp 2KB
851. spfa求最短路.cpp 2KB
844. 走迷宫.cpp 2KB
883. 高斯消元解线性方程组.cpp 2KB
831. KMP字符串.cpp 2KB
853. 有边数限制的最短路.cpp 2KB
1083. Windy数.cpp 2KB
840. 模拟散列表.cpp 2KB
5180. 正方形泳池.cpp 2KB
852. spfa判断负环.cpp 2KB
849. Dijkstra求最短路 I.cpp 2KB
802. 区间和.cpp 2KB
846. 树的重心.cpp 2KB
5166. 对称山脉.cpp 2KB
291. 蒙德里安的梦想.cpp 2KB
4737.cpp 2KB
839. 模拟堆.cpp 2KB
5. 多重背包问题 II.cpp 2KB
233. 数字 1 的个数.cpp 2KB
838. 堆排序.cpp 2KB
845. 八数码.cpp 2KB
5183. 好三元组.cpp 2KB
827. 双链表.cpp 2KB
848. 有向图的拓扑序列.cpp 2KB
240. 食物链.cpp 2KB
1069. 凸多边形的划分.cpp 2KB
900. 整数划分.cpp 2KB
5202. 日常通勤.cpp 2KB
888. 求组合数 IV.cpp 2KB
884. 高斯消元解异或线性方程组.cpp 2KB
792. 高精度减法.cpp 1KB
1081. 度的数量.cpp 1KB
1073. 树的中心.cpp 1KB
850. Dijkstra求最短路 II.cpp 1KB
859. Kruskal算法求最小生成树.cpp 1KB
282. 石子合并.cpp 1KB
5143. 字符串还原.cpp 1KB
902. 最大为 N 的数字组合.cpp 1KB
854. Floyd求最短路.cpp 1KB
292. 炮兵阵地.cpp 1KB
321. 棋盘分割.cpp 1KB
861. 二分图的最大匹配.cpp 1KB
826. 单链表.cpp 1KB
835. Trie字符串统计.cpp 1KB
2827. 范围中美丽整数的数目.cpp 1KB
338. 计数问题.cpp 1KB
3724. 街灯.cpp 1KB
4742.cpp 1KB
860. 染色法判定二分图.cpp 1KB
1084. 数字游戏 II.cpp 1KB
1064. 小国王.cpp 1KB
1082. 数字游戏.cpp 1KB
5166. 对称山脉 y总.cpp 1KB
204. 表达整数的奇怪方式.cpp 1KB
1085. 不要62.cpp 1KB
5133. 奶牛排队.cpp 1KB
10. 有依赖的背包问题.cpp 1KB
793. 高精度乘法.cpp 1KB
841. 字符串哈希.cpp 1KB
836. 合并集合.cpp 1KB
907. 区间覆盖.cpp 1KB
338. 计数问题 dfs.cpp 1KB
487. 金明的预算方案.cpp 1KB
5165. CCC单词搜索 y总.cpp 1KB
327. 玉米田.cpp 1KB
91. 最短Hamilton路径.cpp 1KB
3752.cpp 1KB
143. 最大异或对.cpp 1KB
4. 多重背包问题 I.cpp 1KB
154. 滑动窗口.cpp 1KB
5179. 分组.cpp 1KB
798. 差分矩阵.cpp 1KB
4738.cpp 1KB
847. 图中点的层次.cpp 1KB
785. 快速排序.cpp 1KB
3325.cpp 1KB
837. 连通块中点的数量.cpp 1KB
285. 没有上司的舞会.cpp 1KB
4633.cpp 1KB
5198. 整理书籍.cpp 1KB
896. 最长上升子序列 II.cpp 1KB
1012. 至少有 1 位重复的数字.cpp 1KB
479. 加分二叉树.cpp 1KB
1077. 皇宫看守.cpp 1KB
4672.cpp 1KB
1075. 数字转换.cpp 1KB
1013. 机器分配.cpp 1KB
5081. 重复局面.cpp 1024B
843. n-皇后问题.cpp 1011B
901. 滑雪.cpp 1011B
899. 编辑距离.cpp 1004B
897. 最长公共子序列.cpp 990B
788. 逆序对的数量.cpp 986B
323. 战略游戏.cpp 979B
共 248 条
- 1
- 2
- 3
资源评论
梦回阑珊
- 粉丝: 2473
- 资源: 632
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 信息办公个人求职管理系统-jobgljsp.rar
- 信息办公一流网络JSP网络管理系统 v1.0-yljsp10.rar
- chirpstack学习
- 管家婆辉煌、财贸、工贸、服装,食品,千方模拟狗
- 基于python开发的工业环境老鼠检测+源码+文档(毕业设计&课程设计&项目开发)
- USB转以太网的芯片SR9900全套设计资料包括(参考设计原理图PCB+ Linux -Windows驱动程序+量产工具)
- 信息办公XML考试系统-xmlks.rar
- 基于python开发的无人机图像目标检测+实验数据+开发文档+操作流程+源码(毕业设计&课程设计&项目开发)
- 全球智能商品管理与优化系统
- IDM下载器(电脑小工具)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功