Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98687 | Ghost_Chris | Old Driver Tree | C++ | 解答错误 | 0 | 43 MS | 5640 KB | 1464 | 2023-08-16 12:29:44 |
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 100005; int len[N << 2], t[N << 2], a[N], n; void puup(int x) { t[x] = (t[x << 1] == t[x << 1 | 1] ? t[x << 1] : -1); } void build(int x, int l, int r) { len[x] = r - l + 1; if (l == r) { t[x] = a[l]; return; } int mid = (l + r) >> 1; build(x << 1, l, mid); build(x << 1 | 1, mid + 1, r); puup(x); } void pudo(int x) { if (len[x] == 1) return; if (t[x] != -1) t[x << 1] = t[x << 1 | 1] = t[x]; } int ask(int x, int l, int r, int L, int R, int c) { if (t[x] == c) return min(r, R) - max(l, L) + 1; pudo(x); int mid = (l + r) >> 1, rec = 0; if (l >= L && r <= R) { if (t[x] != -1 && t[x] != c) { t[x] = c; return 0; } rec = ask(x << 1, l, mid, L, R, c) + ask(x << 1 | 1, mid + 1, r, L, R, c); puup(x); return rec; } if (mid >= L) rec = ask(x << 1, l, mid, L, R, c); if (mid + 1 <= R) rec += ask(x << 1 | 1, mid + 1, r, L, R, c); puup(x); return rec; } signed main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); build(1, 1, n); for (int l, r, c,i = 1; i <= n; i++) { cin >> l >> r >> c; cout << ask(1,1,n,l,r,c) << endl; } return 0; }