166pts TLE 求助
查看原帖
166pts TLE 求助
627636
封禁用户楼主2023/2/19 10:00

为什么会有这么奇怪的分数。。

#include <iostream>
#include <algorithm>
using namespace std;
int a[2000005], nxt[2000005], pref[2000005], TLEWA[2000005], cnt[2000005], ans[2000005]; struct seele {int l, r, id;} sing[2000005];
void addd(int x, int v) {while (x <= 2000000) {pref[x] += v; x += x & -x;}} int query(int x) {int summ=0; while (x) {summ += pref[x]; x -= x & -x;} return summ;}
int main() {
int n, c, m, ll=1; cin >> n >> c >> m; for (int i=1; i<=n; i++) {cin >> a[i]; TLEWA[a[i]] = nxt[TLEWA[a[i]]] = i; if (++cnt[a[i]] == 2) addd(i, 1);} for (int i=1; i<=m; i++) {sing[i].id = i; cin >> sing[i].l >> sing[i].r;} sort(sing+1, sing+1+m, [](seele x, seele y){return x.l < y.l;}); for (int i=1; i<=m; i++) {while (ll < sing[i].l) {if (nxt[ll]) {addd(nxt[ll], -1); if (nxt[nxt[ll]]) addd(nxt[nxt[ll]], 1);} ll++;} ans[sing[i].id] = query(sing[i].r);} for (int i=1; i<=m; i++) cout << ans[i] << endl;
}
2023/2/19 10:00
加载中...