QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105457 | #4236. Triangular Logs | marsxiang5902 | WA | 4ms | 17528kb | C++17 | 3.3kb | 2023-05-14 07:05:12 | 2023-05-14 07:05:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5+5, MK = 60, TS = 1<<17;
using st = vector<int>;
int cmbTmp[MK*2];
void comb(st &s1, const st &s2) {
merge(s1.begin(), s1.end(), s2.begin(), s2.end(), cmbTmp, greater<int>());
s1 = st(cmbTmp, cmbTmp+min(MK, (int)(s1.size()+s2.size())));
}
int N, Q, cmp[2][MN], pts[2][MN], n[2], hs[MN], psa[MN]; st seg[TS<<1], ans[MN];
vector<pair<int,int>> upds[MN]; vector<tuple<int,int,int>> qeps[MN];
inline int lb(int z, int x) { return lower_bound(cmp[z], cmp[z]+n[z], x) - cmp[z]; }
inline bool noUpds(int l, int r) { !(psa[l]-psa[r+1]); }
void upd(int y, int h) {
st ns = st{h};
for (comb(seg[y|=TS], ns); y>>=1; )
comb(seg[y], ns);
}
void que(int l, int r, int qn) {
for (l|=TS, ++r|=TS; l < r; l>>=1, r>>=1) {
if (l&1) comb(ans[qn], seg[l++]);
if (r&1) comb(ans[qn], seg[--r]);
}
}
void clr(int y) {
for (seg[y|=TS].clear(); y>>=1; )
seg[y].clear();
}
void cdq(int l, int r, vector<tuple<int,int,int,int,int>> qs) {
if (l > r || qs.empty() || noUpds(l, r)) return;
int m = l+r >> 1;
vector<tuple<int,int,int,int,int>> ql, qr;
for (auto [x0, x1, y0, y1, qn]: qs) {
if (x0 <= m+1 && x1 >= m) {
if (x0 <= m) qeps[x0].emplace_back(y0, y1, qn);
if (x1 > m) qeps[x1].emplace_back(y0, y1, qn);
} else (x1 <= m ? ql : qr).emplace_back(x0, x1, y0, y1, qn);
}
for (int i = m; i >= l; i--) {
for (auto [y, h]: upds[i])
upd(y, h);
for (auto [l, r, qn]: qeps[i])
que(l, r, qn);
}
for (int i = m; i >= l; i--)
for (auto [y, h]: upds[i])
clr(y);
for (int i = m+1; i <= r; i++) {
for (auto [y, h]: upds[i])
upd(y, h);
for (auto [l, r, qn]: qeps[i])
que(l, r, qn);
}
for (int i = m+1; i <= r; i++)
for (auto [y, h]: upds[i])
clr(y);
for (auto [x0, x1, y0, y1, qn]: qs) {
if (x0 <= m+1 && x1 >= m) {
if (x0 <= m) qeps[x0].clear();
if (x1 > m) qeps[x1].clear();
}
}
cdq(l, m, ql); cdq(m+1, r, qr);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
for (int i = 0; i < N; i++)
cin >> pts[0][i] >> pts[1][i] >> hs[i];
for (int z: {0,1}) {
memcpy(cmp[z], pts[z], sizeof pts[0]);
sort(cmp[z], cmp[z]+N);
n[z] = unique(cmp[z], cmp[z]+N) - cmp[z];
for (int i = 0; i < N; i++)
pts[z][i] = lb(z, pts[z][i]);
}
for (int i = 0; i < N; i++) {
upds[pts[0][i]].emplace_back(pts[1][i], hs[i]);
++psa[pts[0][i]];
}
for (int i = n[0]; --i; )
psa[i-1] += psa[i];
vector<tuple<int,int,int,int,int>> qs;
for (int q = 0, x0, y0, x1, y1; q < Q; q++) {
cin >> x0 >> y0 >> x1 >> y1;
x0 = lb(0, x0);
y0 = lb(1, y0);
x1 = lb(0, x1+1)-1;
y1 = lb(1, y1+1)-1;
if (x0 <= x1 && y0 <= y1) qs.emplace_back(x0, x1, y0, y1, q);
}
cdq(0, n[0]-1, qs);
for (int q = 0; q < Q; q++) {
st &s = ans[q];
bool b = 0;
for (int i = 0; i+2 < s.size(); i++)
b |= s[i+1]+s[i+2] > s[i];
printf("%d\n", b);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 17528kb
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 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'