QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243412 | #1429. Hit | memset0 | Compile Error | / | / | C++14 | 3.7kb | 2023-11-08 10:18:31 | 2023-11-08 10:18:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 9, M = 21;
int T, n, t, tn, ta[N], maxl[N], maxr[N], mrk[N], nxt[N][M];
vector<int> pos, ans;
struct node {
int l, r;
} a[N];
struct node {
int l, r, mid, s;
} p[N << 2];
inline bool inside(int l, int r) { return l <= r && maxl[r] >= l; }
inline bool outside(int l, int r) { return l > r || maxr[l] >= r; }
void build(int u, int l, int r) {
p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1, p[u].s = 0;
if (l == r) return;
build(u << 1, l, p[u].mid);
build(u << 1 | 1, p[u].mid + 1, r);
}
void modify(int u, int k, int x) {
if (p[u].l == p[u].r) {
p[u].s += x;
return;
}
modify(k <= p[u].mid ? u << 1 : u << 1 | 1, k, x);
p[u].s = p[u << 1].s + p[u << 1 | 1].s;
}
int query(int u, int l, int r) {
if (p[u].l == l && p[u].r == r) return p[u].s;
if (r <= p[u].mid) return query(u << 1, l, r);
if (l > p[u].mid) return query(u << 1 | 1, l, r);
return query(u << 1, l, p[u].mid) + query(u << 1 | 1, p[u].mid + 1, r);
}
int main() {
#ifdef memset0
freopen("1.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
for (cin >> T; T--;) {
t = tn = 0, ans.clear(), pos.clear();
cin >> n;
ta[++tn] = 1e9 + 10, ta[++tn] = -1e9 - 10;
for (int i = 1; i <= n; i++) {
cin >> a[i].l, ta[++tn] = a[i].l;
cin >> a[i].r, ta[++tn] = a[i].r;
ta[++tn] = a[i].l - 1, ta[++tn] = a[i].l + 1;
ta[++tn] = a[i].r - 1, ta[++tn] = a[i].r + 1;
}
sort(ta + 1, ta + tn + 1);
tn = unique(ta + 1, ta + tn + 1) - ta - 1;
for (int i = 1; i <= n; i++) {
a[i].l = lower_bound(ta + 1, ta + tn + 1, a[i].l) - ta;
a[i].r = lower_bound(ta + 1, ta + tn + 1, a[i].r) - ta;
}
memset(maxl + 1, 0, tn << 2);
memset(maxr + 1, 0, tn << 2);
for (int i = 1; i <= n; i++) {
maxl[a[i].r] = max(maxl[a[i].r], a[i].l);
maxr[a[i].l] = max(maxr[a[i].l], a[i].r);
}
for (int i = 1; i <= tn; i++) {
maxl[i] = max(maxl[i - 1], maxl[i]);
maxr[i] = max(maxr[i - 1], maxr[i]);
}
sort(a + 1, a + n + 1, [](const node &a, const node &b) { return a.r == b.r ? a.l < b.l : a.r < b.r; });
build(1, 1, tn);
for (int i = 1; i <= n; i++)
if (!query(1, a[i].l, a[i].r)) {
modify(1, a[i].r, 1);
ans.push_back(a[i].r);
}
for (int i = 1; i <= n; i++) {
t = max(t, query(1, a[i].l, a[i].r));
}
if (t > 1) {
memset(mrk + 1, 0, tn);
pos.push_back(tn), mrk[tn] = 1;
for (int i = 0; i < M; i++) nxt[tn][i] = tn;
for (int i = tn - 1, j, l, r, mid, s, k; i >= 1; i--) {
l = 0, r = pos.size() - 1, nxt[i][0] = -1;
while (l <= r) {
mid = (l + r) >> 1;
if (!inside(i + 1, pos[mid] - 1)) {
nxt[i][0] = pos[mid];
r = mid - 1;
} else {
l = mid + 1;
}
}
if (!~nxt[i][0]) continue;
for (j = nxt[i][0], k = M - 1, s = t - 2; k >= 0; k--) {
if ((s >> k) & 1) j = nxt[j][k];
}
if (outside(i, j)) continue;
pos.push_back(i), mrk[i] = 1;
for (int j = 1; j < M; j++) {
nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
}
}
int minl = tn;
for (int i = 1; i <= n; i++) minl = min(minl, a[i].l);
if (mrk[minl - 1]) {
--t, ans.clear();
int u = minl - 1;
while (u != tn) ans.push_back(u), u = nxt[u][0];
if (ans.front() == 1) ans.erase(ans.begin());
}
}
cout << t << ' ' << ans.size() << ' ';
for (int i = 0; i < ans.size(); i++) {
cout << ta[ans[i]] << " \n"[i + 1 == ans.size()];
}
}
}
Details
answer.code:9:8: error: redefinition of ‘struct node’ 9 | struct node { | ^~~~ answer.code:6:8: note: previous definition of ‘struct node’ 6 | struct node { | ^~~~ answer.code: In function ‘void build(int, int, int)’: answer.code:15:8: error: request for member ‘l’ in ‘p[u]’, which is of non-class type ‘int’ 15 | p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1, p[u].s = 0; | ^ answer.code:15:20: error: request for member ‘r’ in ‘p[u]’, which is of non-class type ‘int’ 15 | p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1, p[u].s = 0; | ^ answer.code:15:32: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 15 | p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1, p[u].s = 0; | ^~~ answer.code:15:57: error: request for member ‘s’ in ‘p[u]’, which is of non-class type ‘int’ 15 | p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1, p[u].s = 0; | ^ answer.code:17:25: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 17 | build(u << 1, l, p[u].mid); | ^~~ answer.code:18:26: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 18 | build(u << 1 | 1, p[u].mid + 1, r); | ^~~ answer.code: In function ‘void modify(int, int, int)’: answer.code:21:12: error: request for member ‘l’ in ‘p[u]’, which is of non-class type ‘int’ 21 | if (p[u].l == p[u].r) { | ^ answer.code:21:22: error: request for member ‘r’ in ‘p[u]’, which is of non-class type ‘int’ 21 | if (p[u].l == p[u].r) { | ^ answer.code:22:10: error: request for member ‘s’ in ‘p[u]’, which is of non-class type ‘int’ 22 | p[u].s += x; | ^ answer.code:25:20: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 25 | modify(k <= p[u].mid ? u << 1 : u << 1 | 1, k, x); | ^~~ answer.code:26:8: error: request for member ‘s’ in ‘p[u]’, which is of non-class type ‘int’ 26 | p[u].s = p[u << 1].s + p[u << 1 | 1].s; | ^ answer.code:26:22: error: request for member ‘s’ in ‘p[(u << 1)]’, which is of non-class type ‘int’ 26 | p[u].s = p[u << 1].s + p[u << 1 | 1].s; | ^ answer.code:26:40: error: request for member ‘s’ in ‘p[((u << 1) | 1)]’, which is of non-class type ‘int’ 26 | p[u].s = p[u << 1].s + p[u << 1 | 1].s; | ^ answer.code: In function ‘int query(int, int, int)’: answer.code:29:12: error: request for member ‘l’ in ‘p[u]’, which is of non-class type ‘int’ 29 | if (p[u].l == l && p[u].r == r) return p[u].s; | ^ answer.code:29:27: error: request for member ‘r’ in ‘p[u]’, which is of non-class type ‘int’ 29 | if (p[u].l == l && p[u].r == r) return p[u].s; | ^ answer.code:29:47: error: request for member ‘s’ in ‘p[u]’, which is of non-class type ‘int’ 29 | if (p[u].l == l && p[u].r == r) return p[u].s; | ^ answer.code:30:17: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 30 | if (r <= p[u].mid) return query(u << 1, l, r); | ^~~ answer.code:31:16: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 31 | if (l > p[u].mid) return query(u << 1 | 1, l, r); | ^~~ answer.code:32:32: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 32 | return query(u << 1, l, p[u].mid) + query(u << 1 | 1, p[u].mid + 1, r); | ^~~ answer.code:32:62: error: request for member ‘mid’ in ‘p[u]’, which is of non-class type ‘int’ 32 | return query(u << 1, l, p[u].mid) + query(u << 1 | 1, p[u].mid + 1, r); | ^~~