QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72806 | #4236. Triangular Logs | Linshey# | WA | 2ms | 8612kb | C++23 | 2.7kb | 2023-01-19 14:26:08 | 2023-01-19 14:26:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 5;
struct node { int s, ls, rs; } tr[maxn << 6]; int tt;
inline int copy(int u) { return tr[++tt] = tr[u], tt; }
int update(int u, int l, int r, int ps)
{
u = copy(u); tr[u].s++;
if (l == r) return u;
int mid = l + r >> 1;
if (ps <= mid) tr[u].ls = update(tr[u].ls, l, mid, ps); else tr[u].rs = update(tr[u].rs, mid + 1, r, ps);
return u;
}
int sum(int u, int l, int r, int ul, int ur)
{
if (!u) return 0;
if (ul <= l && r <= ur) return tr[u].s;
int mid = l + r >> 1, res = 0;
if (ul <= mid) res += sum(tr[u].ls, l, mid, ul, ur);
if (ur > mid) res += sum(tr[u].rs, mid + 1, r, ul, ur); return res;
}
int a[maxn], b;
void ask(int u, int v, int l, int r, int ul, int ur)
{
if (l > ur || r < ul) return;
if (tr[u].s == tr[v].s) return;
if (l == r) { a[++b] = l; return; }
int mid = l + r >> 1;
ask(tr[u].rs, tr[v].rs, mid + 1, r, ul, ur);
ask(tr[u].ls, tr[v].ls, l, mid, ul, ur);
}
int n, q;
int sx[maxn], sy[maxn], sz[maxn], p[maxn], rt[maxn];
unordered_map<int, int> id;
vector<pair<int, int> > ly[maxn]; int tid;
int c[maxn], d;
inline int pos(int x)
{
int l = 0, r = n;
while (l < r) { int mid = l + r + 1 >> 1; if (sx[p[mid]] <= x) l = mid; else r = mid - 1; }
return l;
}
int main()
{
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%d%d%d", sx + i, sy + i, sz + i), p[i] = i;
sort(p + 1, p + n + 1, [](int x, int y) { return sx[x] < sx[y]; });
for (int i = 1; i <= n; i++)
{
int j = (id[sy[i]] ? id[sy[i]] : (id[sy[i]] = ++tid));
ly[j].push_back({ sx[i], sz[i] });
}
for (int i = 1; i <= n; i++) rt[i] = update(rt[i - 1], 1, 1000000007, sy[p[i]]);
while (q--)
{
int l, u, r, d;
scanf("%d%d%d%d", &l, &u, &r, &d);
int L = pos(l - 1), R = pos(r);
int s = sum(rt[R], 1, 1000000007, u, d) - sum(rt[L], 1, 1000000007, u, d);
if (s <= 2) puts("0");
else if (s >= 62) puts("1");
else
{
b = 0;
ask(rt[R], rt[L], 1, 1000000007, u, d);
d = 0;
for (int i = 1; i <= b; i++)
{
int j = id[a[i]];
for (auto it = lower_bound(ly[j].begin(), ly[j].end(), make_pair(l, 0)); it != ly[j].end() && it->first <= r; it++) c[++d] = it->second;
}
sort(c + 1, c + d + 1);
bool fl = 0;
for (int i = d; i >= 3; i--) if (c[i] <= c[i - 1] + c[i - 2]) { fl = 1; break; }
puts(fl ? "1" : "0");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8612kb
input:
9 5 1 3 3 2 3 1 3 3 4 1 2 1 2 2 5 3 2 9 1 1 2 2 1 6 3 1 5 1 1 1 2 1 1 2 2 1 1 1 3 1 2 3 2 1 1 3 3
output:
0 1 1 0 1
result:
wrong answer 3rd lines differ - expected: '0', found: '1'