이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
//#include <bits/extc++.h>
#define ll long long
#define maxn 300005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds;
//template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//find by order, order of key
struct obj {
int x, y, z, type, id;
obj() {
x = 0, y = 0, z = 0, type = 0, id = 0;
}
obj(int a, int b, int c, int d) {
x = a, y = b, z = c, type = d, id = 0;
}
};
vector<obj> v, v2;
bool cut[maxn];
inline bool cmp(obj a, obj b) {
if (a.z == b.z) return a.type < b.type;
return a.z > b.z;
}
inline bool cmp2(obj a, obj b) {
if (a.x == b.x) {
if (a.y == b.y) return a.type < b.type;
return a.y < b.y;
}
return a.x < b.x;
}
vector<int> nx, ny;
inline void compress(vector<int> &a) {
sort(a.begin(), a.end());
a.resize(int(unique(a.begin(), a.end()) - a.begin()));
}
struct BIT{
int bit[maxn];
void modify(int ind, int val) {
for (;ind < maxn;ind += ind & (-ind)) bit[ind] += val;
}
int query(int ind) {
int ret = 0;
for (;ind > 0;ind -= ind & (-ind)) ret += bit[ind];
return ret;
}
} bx, by, bb;
int ans[maxn];
int main() {
io
int n, q;
cin >> n >> q;
for (int i = 0;i < n;i++) {
int s, t;
cin >> s >> t;
v.push_back(obj(s, t, s + t, 0));
nx.push_back(s);
ny.push_back(t);
}
for (int i = 0;i < q;i++) {
int x, y, z;
cin >> x >> y >> z;
v.push_back(obj(x, y, z, 1));
cut[i] = z > x + y;
v.back().id = i;
nx.push_back(x);
ny.push_back(y);
}
sort(v.begin(), v.end(), cmp);
//for (int i:nx) cout << i << " ";
//cout << endl;
compress(nx), compress(ny);
//for (int i:nx) cout << i << " ";
//cout << endl;
for (auto &i:v) {
i.x = lower_bound(nx.begin(), nx.end(), i.x) - nx.begin() + 1;
i.y = lower_bound(ny.begin(), ny.end(), i.y) - ny.begin() + 1;
//cout << i.x << " " << i.y << " " << i.z << " " << i.type << endl;
}
int les = n;
for (int i = 0;i < v.size();i++) {
if (v[i].type == 0) {
bx.modify(v[i].x, 1);
by.modify(v[i].y, 1);
v2.push_back(obj(maxn - 1 - v[i].x, maxn - 1 - v[i].y, 0, 0));
les--;
} else {
if (cut[v[i].id]) {
ans[v[i].id] = n - les - bx.query(v[i].x - 1) - by.query(v[i].y - 1);
} else {
//ans[v[i].id] = n - bx.query(v[i].x - 1) - by.query(v[i].y - 1);
v2.push_back(obj(maxn - v[i].x - 1, maxn - v[i].y - 1, 0, 1));
v2.back().id = v[i].id;
}
}
}
sort(v2.begin(), v2.end(), cmp2);
for (int i = 0;i < v2.size();i++) {
if (v2[i].type == 0) {
bb.modify(v2[i].y, 1);
} else {
ans[v2[i].id] = bb.query(v2[i].y);
}
}
for (int i = 0;i < q;i++) cout << ans[i] << "\n";
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
*/
컴파일 시 표준 에러 (stderr) 메시지
examination.cpp: In function 'int main()':
examination.cpp:97:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<obj>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 0;i < v.size();i++) {
| ~~^~~~~~~~~~
examination.cpp:114:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<obj>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for (int i = 0;i < v2.size();i++) {
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |