和上题类似,同样是区间染色,但是此题范围0 - 8000,不用离散化,暴力统计即可,
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll Lcm(ll a, ll b) { return a / gcd(a, b) * b; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } ll readll() { ll x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } void Put(ll x) { if (x < 0) putchar('-'), x *= -1; if (x > 9) Put(x / 10); putchar(x % 10 + '0'); } int n, last; int vis[maxn]; int a[maxn]; void Push_down(int i) { if (a[i] == -1) return; a[i << 1] = a[i << 1 | 1] = a[i]; a[i] = -1; } void update(int i, int l, int r, int L, int R, int v) { if (L <= l && R >= r) { a[i] = v; return; } Push_down(i); int mid = l + r >> 1; if (L <= mid) update(i << 1, l, mid, L, R, v); if (R > mid) update(i << 1 | 1, mid + 1, r, L, R, v); } void query(int i, int l, int r) { if (l == r) { if (a[i] != -1 && a[i] != last) vis[a[i]]++; last = a[i]; return; } Push_down(i); int mid = l + r >> 1; query(i << 1, l, mid); query(i << 1 | 1, mid + 1, r); } int main() { int x, y, z; while (~scanf("%d", &n)) { memset(vis, 0, sizeof vis); memset(a, -1, sizeof a); for (int i = 0; i < n; i++) { x = readint(); y = readint(); z = readint(); update(1, 1, 8000, x + 1, y, z); } last = -1; query(1, 1, 8000); for (int i = 0; i <= 8000; i++) if (vis[i]) printf("%d %d ", i, vis[i]); puts(""); } }