#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = (int)(1e5)+5;
struct query {
int X;
int Y;
int Z;
int i;
};
vector<query> vec;
vector<int> byB;
unordered_map<int, int> cnt;
int ans[MAXN];
const int K = 330;
int arr[MAXN];
vector<int> keep[MAXN/K + 5];
int main() {
int N, Q;
cin >> N >> Q;
for (int i = 0; i < N; i++) {
arr[i] = -1;
int A, B;
cin >> A >> B;
vec.push_back({A, B, -1, -1});
byB.push_back(B);
}
sort(byB.begin(), byB.end());
int c = 1;
for (int i = 1; i < N; i++) {
if (byB[i] != byB[i-1]) {
cnt[byB[i-1]] = c;
}
c++;
}
cnt[byB[N-1]] = c;
for (int i = 0; i < Q; i++) {
int X, Y, Z;
cin >> X >> Y >> Z;
vec.push_back({X, Y, Z, i});
}
sort(vec.begin(), vec.end(), [](const query& lhs, const query& rhs) {
if (lhs.X != rhs.X) return lhs.X > rhs.X;
if (lhs.Y != rhs.Y) return lhs.Y > rhs.Y;
return lhs.i < rhs.i;})
;
for (query q : vec) {
if (q.i != -1) {
int low = 0;
int high = N-1;
while (low < high) {
int mid = (low + high)/2;
if (byB[mid] >= q.Y) {
high = mid;
}
else {
low = mid+1;
}
}
if (byB[high] >= q.Y) {
for (int i = N-1; i >= high;) {
if ((i/K)*K >= high) {
if (keep[i/K].size() > 0) {
low = 0;
high = keep[i/K].size()-1;
while (low < high) {
int mid = (low + high)/2;
if (keep[i/K][mid] >= q.Z) {
high = mid;
}
else {
low = mid+1;
}
}
if (keep[i/K][high] >= q.Z) {
ans[q.i] += keep[i/K].size() - high;
}
}
i = (i/K)*K - 1;
}
else {
if (arr[i] >= q.Z) {
ans[q.i]++;
}
i--;
}
}
}
}
else {
cnt[q.Y]--;
arr[cnt[q.Y]] = q.X + q.Y;
keep[cnt[q.Y]/K].push_back(q.X + q.Y);
sort(keep[cnt[q.Y]/K].begin(), keep[cnt[q.Y]/K].end());
}
}
for (int i = 0; i < Q; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
25 ms |
620 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1159 ms |
9144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1159 ms |
9144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
25 ms |
620 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |