# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
372969 | luciocf | Examination (JOI19_examination) | C++14 | 3062 ms | 267056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 2e5+10;
struct BIT2D
{
map<int, int> bit[maxn];
void upd(int x, int y, int v)
{
for (int i = x; i < maxn; i += (i&-i))
for (int j = y; j < maxn; j += (j&-j))
bit[i][j] += v;
}
int soma(int x, int y)
{
int ans = 0;
for (int i = x; i > 0; i -= (i&-i))
for (int j = y; j > 0; j -= (j&-j))
ans += bit[i][j];
return ans;
}
} BIT;
struct Query
{
int x, y, z, ind;
} query[maxn];
pii a[maxn];
int ans[maxn];
int main(void)
{
int n, q;
scanf("%d %d", &n, &q);
map<int, int> mpx, mpy;
for (int i = 1; i <= n; i++)
{
scanf("%d %d", &a[i].ff, &a[i].ss);
mpx[a[i].ff] = 0;
mpy[a[i].ss] = 0;
}
for (int i = 1; i <= q; i++)
{
scanf("%d %d %d", &query[i].x, &query[i].y, &query[i].z);
query[i].ind = i;
mpx[query[i].x] = 0;
mpy[query[i].y] = 0;
}
int aux = 0;
for (auto &x: mpx)
x.second = ++aux;
aux = 0;
for (auto &x: mpy)
x.second = ++aux;
sort(a+1, a+n+1, [&] (pii a, pii b) {return a.ff+a.ss > b.ff+b.ss;});
sort(query+1, query+q+1, [&] (Query a, Query b) {return a.z > b.z;});
int ptr = 1;
for (int i = 1; i <= q; i++)
{
while (ptr <= n && a[ptr].ff+a[ptr].ss >= query[i].z)
{
BIT.upd(maxn-mpx[a[ptr].ff], maxn-mpy[a[ptr].ss], 1);
ptr++;
}
ans[query[i].ind] = BIT.soma(maxn-mpx[query[i].x], maxn-mpy[query[i].y]);
}
for (int i = 1; i <= q; i++)
printf("%d\n", ans[i]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |