# BZOJ 3809 Gty的二逼妹子序列 | 莫队 + 分块

Autumn和Bakser又在研究Gty的妹子序列了！但他们遇到了一个难题。

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
template <class T>
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}
#define space putchar(' ')
#define enter putchar('\n')

const int N = 100005, M = 1000005, B = 340;
int n, m, a[N], cnt[N], bcnt[B], ans[M], pl = 1, pr;
#define st(x) (((x) - 1) * B + 1)
#define ed(x) min(n, (x) * B)
#define bel(x) (((x) - 1) / B + 1)
struct query {
int id, l, r, a, b;
bool operator < (const query &b) const {
return bel(l) == bel(b.l) ? r < b.r : l < b.l;
}
} q[M];

if(x == 1 && !cnt[p]) bcnt[bel(p)]++;
cnt[p] += x;
if(x == -1 && !cnt[p]) bcnt[bel(p)]--;
}
int ret = 0;
for(int i = l; i <= r; i++)
ret += cnt[i] > 0;
return ret;
}
if(bel(l) == bel(r))
for(int i = bel(l) + 1; i < bel(r); i++)
ret += bcnt[i];
return ret;
}

int main(){

for(int i = 1; i <= n; i++) read(a[i]);
for(int i = 1; i <= m; i++)
sort(q + 1, q + m + 1);
for(int i = 1; i <= m; i++){