#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point{
int x, y, z, idx;
};
namespace BIT{
const int OFFSET = 10;
int p = 0;
vector<pair<int, int>> s;
void init(int n){
s.resize(n + OFFSET*2);
}
int query(int pos){
int r = 0;
for (pos=s.size()-pos-OFFSET; pos; pos -= pos & (-pos))
r += (s[pos].second == p) * s[pos].first;
return r;
}
void update(int pos, int v){
for (pos=s.size()-pos-OFFSET; pos < s.size(); pos += pos & (-pos)){
if (s[pos].second != p) s[pos] = {0, p};
s[pos].first += v;
}
}
void reset(){
p++;
}
}
vector<point> a;
vector<int> result;
void cdq(int start, int end){
if (start == end) return;
int mid = (start+end)>>1;
cdq(start, mid); cdq(mid+1, end);
vector<pair<point, bool>> s;
int lptr = start;
for (int rptr=mid+1; rptr<=end; rptr++){
while (lptr <= mid && pair<int, int> (a[lptr].y, -a[lptr].idx) >= pair<int, int> (a[rptr].y, -a[rptr].idx))
s.emplace_back(a[lptr++], 0);
s.emplace_back(a[rptr], 1);
}
while (lptr <= mid) s.emplace_back(a[lptr++], 0);
BIT::reset();
for (const pair<point, bool> &c: s){
if (c.second && c.first.idx != -1)
result[c.first.idx] += BIT::query(c.first.x);
if (!c.second && c.first.idx == -1)
BIT::update(c.first.x, 1);
}
for (int i=0; i<s.size(); i++)
a[start+i] = s[i].first;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
for (int i=0; i<n; i++){
int s, t; cin >> s >> t;
a.push_back({s, t, s+t, -1});
}
for (int i=0; i<q; i++){
int x, y, z; cin >> x >> y >> z;
a.push_back({x, y, z, i});
}
sort(a.begin(), a.end(), [](const point &a, const point &b){
return a.x < b.x;
});
for (int lptr=0, rptr=0; lptr<a.size(); lptr=rptr){
int value = a[lptr].x;
while (rptr<a.size() && value == a[rptr].x)
a[rptr++].x = lptr;
}
BIT::init(n+q);
sort(a.begin(), a.end(), [](const point &a, const point &b){
return pair<int, int> (a.z, a.idx) > pair<int, int> (b.z, b.idx);
});
result.resize(q);
cdq(0, a.size()-1);
for (int v: result) cout << v << "\n";
}
Compilation message
examination.cpp: In function 'void BIT::update(int, int)':
examination.cpp:22:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (pos=s.size()-pos-OFFSET; pos < s.size(); pos += pos & (-pos)){
| ~~~~^~~~~~~~~~
examination.cpp: In function 'void cdq(int, int)':
examination.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<point, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i=0; i<s.size(); i++)
| ~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:69:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int lptr=0, rptr=0; lptr<a.size(); lptr=rptr){
| ~~~~^~~~~~~~~
examination.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while (rptr<a.size() && value == a[rptr].x)
| ~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Incorrect |
4 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
13060 KB |
Output is correct |
2 |
Correct |
176 ms |
13032 KB |
Output is correct |
3 |
Correct |
174 ms |
13052 KB |
Output is correct |
4 |
Correct |
166 ms |
13028 KB |
Output is correct |
5 |
Correct |
136 ms |
13028 KB |
Output is correct |
6 |
Incorrect |
116 ms |
13040 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
13060 KB |
Output is correct |
2 |
Correct |
176 ms |
13032 KB |
Output is correct |
3 |
Correct |
174 ms |
13052 KB |
Output is correct |
4 |
Correct |
166 ms |
13028 KB |
Output is correct |
5 |
Correct |
136 ms |
13028 KB |
Output is correct |
6 |
Incorrect |
116 ms |
13040 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Incorrect |
4 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |