int n, m, l, r, x, a[N], ans[N]; int tot; structnode { int x, num, id, typ; booloperator< (const node& a) const {return x < a.x;} } q[N << 1];
int tr[N]; constexprintlowbit(int x){return x & -x;} voidadd(int x, int c){for (; x < N; x += lowbit(x)) tr[x] += c;} intask(int x){int res = 0; for (; x; x -= lowbit(x)) res += tr[x]; return res;}
void _main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) { cin >> l >> r >> x; q[++tot] = node{l - 1, x, i, -1}; q[++tot] = node{r, x, i, 1}; } sort(q + 1, q + tot + 1); for (int i = 1, j = 1; i <= tot; i++) { for (; j <= q[i].x; j++) add(a[j], 1); ans[q[i].id] += q[i].typ * ask(q[i].num); } for (int i = 1; i <= m; i++) cout << ans[i] << '\n'; } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
int t = 1; for (/*cin >> t*/; t--; ) _main(); return0; }
int n, m, tot, ans[N]; structpos { int x, y; booloperator< (const pos& x) const {return y < x.y;} } a[N]; structnode { int r, l, id, typ; booloperator< (const node& x) const {return l < x.l;} } q[N << 2];
int tr[M]; constexprintlowbit(int x){return x & -x;} voidadd(int x, int c){for (; x < M; x += lowbit(x)) tr[x] += c;} intask(int x){int res = 0; for (; x >= 1; x -= lowbit(x)) res += tr[x]; return res;}
void _main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; for (int i = 1; i <= m; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; //x1++, y1++, x2++, y2++; q[++tot] = node{x2, y2, i, 1}; if (x1 >= 1) q[++tot] = node{x1 - 1, y2, i, -1}; if (y1 >= 1) q[++tot] = node{x2, y1 - 1, i, -1}; if (x1 >= 1 && y1 >= 1) q[++tot] = node{x1 - 1, y1 - 1, i, 1}; } sort(a + 1, a + n + 1), sort(q + 1, q + tot + 1); for (int i = 0, j = 1, k = 1; i <= n; i++) { for (; j <= n && a[j].y == i; j++) add(a[j].x + 1, 1); debug(q[k].l); for (; k <= tot && q[k].l == i; k++) ans[q[k].id] += q[k].typ * ask(q[k].r + 1); } for (int i = 1; i <= m; i++) cout << ans[i] << '\n'; } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
int t = 1; for (/*cin >> t*/; t--; ) _main(); return0; }
int n, m, a[N], vis[N], ans[N]; structnode { int l, r, id; } q[N];
int tr[N]; constexprintlowbit(int x){return x & -x;} voidupdate(int x, int c){ for (; x <= n; x += lowbit(x)) tr[x] += c; } intquery(int x){ int res = 0; for (; x != 0; x -= lowbit(x)) res += tr[x]; return res; }
void _main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> m; for (int i = 1; i <= m; i++) cin >> q[i].l >> q[i].r, q[i].id = i; sort(q + 1, q + m + 1, [](const node& x, const node& y) -> bool { return x.r < y.r; }); int nxt = 1; for (int i = 1; i <= m; i++) { for (int j = nxt; j <= q[i].r; j++) { if (vis[a[j]]) update(vis[a[j]], -1); vis[a[j]] = j, update(j, 1); } ans[q[i].id] = query(q[i].r) - query(q[i].l - 1); nxt = q[i].r + 1; } for (int i = 1; i <= m; i++) cout << ans[i] << '\n'; } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
int t = 1; for (/*cin >> t*/; t--; ) _main(); return0; }
int n, c, m, a[N], ans[N]; structnode { int l, r, id; } q[N];
int tr[N]; constexprintlowbit(int x){return x & -x;} voidupdate(int x, int c){ for (; x <= n; x += lowbit(x)) tr[x] += c; } intquery(int x){ int res = 0; for (; x != 0; x -= lowbit(x)) res += tr[x]; return res; }
int mp[N], vis1[N], vis2[N];
void _main() { read(n), read(c), read(m); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= m; i++) read(q[i].l), read(q[i].r), q[i].id = i; sort(q + 1, q + m + 1, [](const node& x, const node& y) -> bool { return x.r < y.r; }); int nxt = 1; for (int i = 1; i <= m; i++) { for (int j = nxt; j <= q[i].r; j++) { if (!vis1[a[j]]) vis1[a[j]] = j; else { if (!vis2[a[j]]) { update(vis1[a[j]], 1); } else { update(vis2[a[j]], 1); update(vis1[a[j]], -1); vis1[a[j]] = vis2[a[j]]; } vis2[a[j]] = j; } } ans[q[i].id] = query(q[i].r) - query(q[i].l - 1); nxt = q[i].r + 1; }
for (int i = 1; i <= m; i++) write(ans[i]), putchar('\n'); flush(); } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
int t = 1; for (/*cin >> t*/; t--; ) _main(); return0; }
int tr[N]; constexprintlowbit(int x){return x & -x;} voidadd(int x, int c){ for (; x < N; x += lowbit(x)) tr[x] = max(tr[x], c); } intask(int x){ int res = 0; for (; x != 0; x -= lowbit(x)) res = max(res, tr[x]); return res; }
void _main() { cin >> n; for (int i = 1; i <= 5 * n; i++) cin >> a[i], pos[a[i]].emplace_back(i); for (int i = 1; i <= 5 * n; i++) cin >> b[i]; // 变LIS,二维数点权值前缀max for (int i = 1; i <= 5 * n; i++) { for (int j = 4; j >= 0; j--) { int x = pos[b[i]][j]; add(x, ask(x - 1) + 1); } } cout << ask(5 * n); } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr);
int t = 1; for (/*cin >> t*/; t--; ) _main(); return0; }