询问区间有种个颜色,单点修改某个位置。
修改次数<=1000维护pre[i]为前一个与当前位置颜色一样的位置。
询问时以pre为关键字sort,lower_bound找pre<x的就是当前区间的答案 因为修改次数少,所以每次重新搞就行。#include#include #include #define N 10010#define B 100#define bel(x) ((x-1)/B+1)#define st(x) ((x-1)*B+1)#define ed(x) (x==bel(n)?n:(x*B))using namespace std;int n,q,a[N],pre[N],spre[N],lst[N*100],x,y;char op[3];int read(){ int ans=0,fu=1; char j=getchar(); for (;j<'0' || j>'9';j=getchar()) if (j=='-') fu=-1; for (;j>='0' && j<='9';j=getchar()) ans*=10,ans+=j-'0'; return ans*fu;}int query(int x,int y){ int ret=0; if (bel(x)==bel(y)) { for (int i=x;i<=y;i++) if (pre[i] #include #include #define N 10010#define B 100#define bel(x) ((x-1)/B+1)#define st(x) ((x-1)*B+1)#define ed(x) (x==bel(n)?n:(x*B))using namespace std;int n,q,a[N],pre[N],spre[N],lst[N*100],x,y;char op[3];int read(){ int ans=0,fu=1; char j=getchar(); for (;j<'0' || j>'9';j=getchar()) if (j=='-') fu=-1; for (;j>='0' && j<='9';j=getchar()) ans*=10,ans+=j-'0'; return ans*fu;}int query(int x,int y){ int ret=0; if (bel(x)==bel(y)) { for (int i=x;i<=y;i++) if (pre[i]