#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 && a[lptr].y >= a[rptr].y)
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 a.z > b.z;
});
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 |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
5 ms |
812 KB |
Output is correct |
8 |
Correct |
5 ms |
852 KB |
Output is correct |
9 |
Correct |
6 ms |
816 KB |
Output is correct |
10 |
Correct |
5 ms |
840 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Incorrect |
4 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
13568 KB |
Output is correct |
2 |
Correct |
193 ms |
13440 KB |
Output is correct |
3 |
Correct |
193 ms |
13480 KB |
Output is correct |
4 |
Correct |
146 ms |
13412 KB |
Output is correct |
5 |
Correct |
130 ms |
13452 KB |
Output is correct |
6 |
Incorrect |
109 ms |
13448 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
13568 KB |
Output is correct |
2 |
Correct |
193 ms |
13440 KB |
Output is correct |
3 |
Correct |
193 ms |
13480 KB |
Output is correct |
4 |
Correct |
146 ms |
13412 KB |
Output is correct |
5 |
Correct |
130 ms |
13452 KB |
Output is correct |
6 |
Incorrect |
109 ms |
13448 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 |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
5 ms |
812 KB |
Output is correct |
8 |
Correct |
5 ms |
852 KB |
Output is correct |
9 |
Correct |
6 ms |
816 KB |
Output is correct |
10 |
Correct |
5 ms |
840 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Incorrect |
4 ms |
724 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |