0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 16:18:46 +00:00
Baoshuo Ren 2022-02-07 22:06:00 +08:00
parent d14c69a1bf
commit 1aed9faffb
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

43
AcWing/802/802.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <algorithm>
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
#define endl '\n'
int n, m, x, c, l, r, data[300005], sum[300005];
std::vector<int> nums;
std::vector<std::pair<int, int>> adds, queries;
inline int find(int x) {
auto pos = std::lower_bound(nums.begin(), nums.end(), x);
return pos == nums.end() || *pos != x ? 0 : pos - nums.begin() + 1;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x >> c;
nums.push_back(x);
adds.push_back(std::make_pair(x, c));
}
for (int i = 1; i <= m; i++) {
cin >> l >> r;
queries.push_back(std::make_pair(l, r));
nums.push_back(l);
nums.push_back(r);
}
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
for (const auto& add : adds) {
data[find(add.first)] += add.second;
}
for (int i = 1; i <= nums.size(); i++) {
sum[i] = sum[i - 1] + data[i];
}
for (const auto& query : queries) {
cout << sum[find(query.second)] - sum[find(query.first) - 1] << endl;
}
return 0;
}