이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
const int MAXN = 6e5 + 5;
#define ALL(a) (a).begin(), (a).end()
#define LB(a, x) (lower_bound(ALL(a), x) - (a).begin() + 1)
struct student {
int x, y, z;
student(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
};
struct query {
int x, y, z, p;
query(int x = 0, int y = 0, int z = 0, int p = 0) : x(x), y(y), z(z), p(p) {}
};
struct node {
int N;
vector<int> value;
vector<int> BIT;
node(int N = 0, vector<int> value = vector<int>(), vector<int> BIT = vector<int>()) : N(N), value(value), BIT(BIT) {}
void init() {
sort(ALL(value));
value.resize(unique(ALL(value)) - value.begin());
N = value.size() + 5;
BIT.assign(N + 1, 0);
}
void update(int x) {
x = LB(value, x);
for(; x; x -= (x & -x)) BIT[x]++;
}
int get(int x) {
x = LB(value, x);
int res = 0;
for(; x <= N; x += (x & -x))
res += BIT[x];
return res;
}
};
int N, Q;
student a[MAXN];
query b[MAXN];
int ans[MAXN];
struct segment_tree {
int N;
node tree[MAXN * 4];
void init(int _N) {
N = _N;
}
void build() {
for(int i = 1; i <= 4 * N ; i++) {
tree[i].init();
}
}
void update(int i, int l, int r, int pos, int val) {
if (l > pos || pos > r) return;
tree[i].update(val);
if (l == r) return;
int mid = (l + r) >> 1;
update(i << 1, l, mid, pos, val);
update(i << 1 | 1, mid + 1, r, pos, val);
}
int get(int i, int l, int r, int L, int R, int val) {
if (L > r || l > R) return 0;
if (L <= l && r <= R) return tree[i].get(val);
int mid = (l + r) >> 1;
return get(i << 1, l, mid, L, R, val) + get(i << 1 | 1, mid + 1, r, L, R, val);
}
void update(int p, int x) {
return update(1, 1, N, p, x);
}
int get(int l, int r, int x) {
return get(1, 1, N, l, r, x);
}
} ST;
signed main() {
#define TASK ""
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> Q;
for(int i = 1; i <= N; i++) {
auto &[x, y, z] = a[i];
cin >> x >> y;
z = x + y;
}
for(int i = 1; i <= Q; i++) {
auto &[x, y, z, p] = b[i];
cin >> x >> y >> z;
p = i;
}
vector<int> comp;
for(int i = 1; i <= N; i++) {
auto [x, y, z] = a[i];
comp.emplace_back(x);
comp.emplace_back(y);
comp.emplace_back(z);
}
for(int i = 1; i <= Q; i++) {
auto [x, y, z, p] = b[i];
comp.emplace_back(x);
comp.emplace_back(y);
comp.emplace_back(z);
}
sort(ALL(comp));
comp.resize(unique(ALL(comp)) - comp.begin());
const int M = comp.size();
for(int i = 1; i <= N; i++) {
auto &[x, y, z] = a[i];
x = LB(comp, x);
y = LB(comp, y);
z = LB(comp, z);
}
for(int i = 1; i <= Q; i++) {
auto &[x, y, z, p] = b[i];
x = LB(comp, x);
y = LB(comp, y);
z = LB(comp, z);
}
ST.init(M);
for(int i = 1; i <= N; i++) {
int id = 1, l = 1, r = M;
int p = a[i].x;
int v = a[i].y;
while(l < r) {
int m = (l + r) / 2;
if(p <= m) {
id = id * 2;
r = m;
} else {
id = id * 2 + 1;
l = m + 1;
}
}
while(id >= 1) {
ST.tree[id].value.emplace_back(v);
id >>= 1;
}
}
ST.build();
sort(a + 1, a + N + 1, [&](const student a, const student b) {
if(a.z != b.z) return a.z > b.z;
if(a.x != b.x) return a.x > b.x;
return a.y > b.y;
});
sort(b + 1, b + Q + 1, [&](const query a, const query b) {
if(a.z != b.z) return a.z > b.z;
if(a.x != b.x) return a.x > b.x;
if(a.y != b.y) return a.y > b.y;
return a.p > b.p;
});
int j = 1;
for(int i = 1; i <= Q; i++) {
while(j <= N and a[j].z >= b[i].z) {
ST.update(a[j].x, a[j].y);
j++;
}
ans[b[i].p] = ST.get(b[i].x, M, b[i].y);
}
for(int i = 1; i <= Q; i++) cout << ans[i] << "\n";
return (0 ^ 0);
}
컴파일 시 표준 에러 (stderr) 메시지
examination.cpp: In function 'int main()':
examination.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(TASK ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(TASK ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |