1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <bits/stdc++.h> #define eb emplace_back const int N = 1e5 + 100, inf = 0x3f3f3f3f; int n, nn, tot, as1 = 0, as2 = 0; struct LT { #define lc (u << 1) #define rc ((u << 1) | 1) #define mid ((l + r) >> 1) int tg[N * 24], v[N * 24]; void dw(int u) { if (tg[u]) { tg[lc] ^= tg[u], v[lc] ^= tg[u]; tg[rc] ^= tg[u], v[rc] ^= tg[u]; tg[u] = 0; } } void mdf(int ql, int qr, int d, int u = 1, int l = 1, int r = nn) { if (ql <= l && r <= qr) return tg[u] ^= d, void(v[u] ^= d); dw(u); if (ql <= mid) mdf(ql, qr, d, lc, l, mid); if (qr > mid) mdf(ql, qr, d, rc, mid + 1, r); } int ask(int pos, int u = 1, int l = 1, int r = nn) { if (l == r) return v[u]; dw(u); return pos <= mid ? ask(pos, lc, l, mid) : ask(pos, rc, mid + 1, r); } #undef lc #undef rc #undef mid } lt; std::array<int, 3> q[N * 3]; std::vector<int> xx; int lb(int x){ return std::lower_bound(xx.begin(), xx.end(), x) - xx.begin() + 1; } int main() { scanf("%d", &n); xx.eb(0); for (int i = 1, t, l, r, w; i <= n; ++i) { scanf("%d %d %d", &t, &l, &r); if (t == 1) { scanf("%d", &w); q[++tot] = {l, r, w}; xx.eb(l), xx.eb(r), xx.eb(l - 1), xx.eb(r + 1); } else if (t == 2) q[++tot] = {l, l, r}, xx.eb(l), xx.eb(l - 1), xx.eb(l + 1); else q[++tot] = {-inf, l - 1, r}, q[++tot] = {l + 1, inf, r}, xx.eb(l), xx.eb(l - 1), xx.eb(l + 1); } std::sort(xx.begin(), xx.end()); xx.erase(std::unique(xx.begin(), xx.end()), xx.end()); nn = xx.size(); for (int i = 1; i <= tot; ++i) lt.mdf(lb(q[i][0]), lb(q[i][1]), q[i][2]); for (int i = xx.size(), t; i; --i) { t = lt.ask(i); if (t > as1) as1 = t, as2 = xx[i - 1]; else if (t == as1 && std::abs(xx[i - 1]) < std::abs(as2)) as2 = xx[i - 1]; } printf("%d %d\n", as1, as2); return 0; }
|