이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1e5 + 7;
vector<int> tree[mxN * 4], x[mxN * 4], y[mxN * 4];
ii a[mxN], b[mxN], sum[mxN];
int n, q;
void Build(int j = 1, int l = 1, int r = n)
{
if (l == r)
{
tree[j].push_back(a[l].se);
x[j].push_back(b[sum[l].se].fi);
y[j].push_back(b[sum[l].se].se);
return;
}
int mid = (l + r) / 2;
Build(j * 2, l, mid);
Build(j * 2 + 1, mid + 1, r);
merge(tree[j * 2].begin(), tree[j * 2].end(), tree[j * 2 + 1].begin(), tree[j * 2 + 1].end(), back_inserter(tree[j]));
merge(x[j * 2].begin(), x[j * 2].end(), x[j * 2 + 1].begin(), x[j * 2 + 1].end(), back_inserter(x[j]));
merge(y[j * 2].begin(), y[j * 2].end(), y[j * 2 + 1].begin(), y[j * 2 + 1].end(), back_inserter(y[j]));
}
int Get1(int u, int v, int j = 1, int l = 1, int r = n)
{
if (a[r].fi < u)
return 0;
if (a[l].fi >= u)
return r - l + 1 - (lower_bound(tree[j].begin(), tree[j].end(), v) - tree[j].begin());
int mid = (l + r) / 2;
return Get1(u, v, j * 2, l, mid) + Get1(u, v, j * 2 + 1, mid + 1, r);
}
int Get2(int total, int u, int v, int j = 1, int l = 1, int r = n)
{
if (sum[r].fi < total)
return 0;
if (sum[l].fi >= total)
return r - l + 1 - (lower_bound(x[j].begin(), x[j].end(), u) - x[j].begin()) - (lower_bound(y[j].begin(), y[j].end(), v) - y[j].begin());
int mid = (l + r) / 2;
return Get2(total, u, v, j * 2, l, mid) + Get2(total, u, v, j * 2 + 1, mid + 1, r);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i].fi >> a[i].se;
b[i] = a[i];
sum[i].fi = a[i].fi + a[i].se;
sum[i].se = i;
}
sort(sum + 1, sum + n + 1);
sort(a + 1, a + n + 1);
Build();
for (int i = 1; i <= q; i++)
{
int u, v, c;
cin >> u >> v >> c;
if (u + v >= c)
cout << Get1(u, v) << '\n';
else
cout << Get2(c, u, v) << '\n';
}
}
# | 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... |