Title: Give a sequence, ask a sequence, there are more than two times the number of colors.
Idea: It looks like an HH necklace.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1000010using namespace Std;struct ask{int X,y,_id;bool operator < (const ASK &a) Const {return x < a.x;} void Read (int p) {scanf ("%d%d", &x,&y); _id = P;}} Ask[max];int cnt,cols,asks;int fenwick[max];int src[max];int last[max],next[max];int T[MAX];int ans[MAX];inline void Fix (int x,int c) {if (!x) return, for (; x <= cnt; x + = X&-x) fenwick[x] + = C;} inline int getsum (int x) {int re = 0;for (; x; x = x&-x) re + + Fenwick[x];return re;} int main () {cin >> cnt >> cols >> asks;for (int i = 1; I <= cnt; ++i) scanf ("%d", &src[i]); for (int i = 1; I <= CNT; ++i) {if (++t[src[i] = = 2) Fix (i,1), if (Last[src[i]]) next[last[src[i]] [= i;last[src[i]] = i;} for (int i = 1;i <= asks; ++i) Ask[i]. Read (i), sort (ask + 1,ask + asks + 1), ask[0].x = 1;for (int i = 1; I <= asks; ++i) {for (int j = ask[i-1].x; J < ask[ i].x; ++J) {Fix (next[j],-1); Fix (Next[next[j]],1);} ANS[ASK[I]._ID] = getsum (ASK[I].Y);} for (int i = 1; I <= asks; ++i) printf ("%d\n", Ans[i]); return 0;}
Bzoj 2743 heoi 2012 Flower Dressing Array