【SDOI2008】郁闷的小J

传送门

看到过一些神仙做法

离线二维偏序哈希做

然而我并没有想那么多

管他那么多,上个map+map+树状数组10minA10minA

直接对于每一种数都维护一个mapmap

取下来就直接单点先减再加,维护一下每个位置放的什么书就可以了

luoguluogu即使用unorderedmapunordered-map不开O2O_2也会TT一个点

不管了

#include<bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
inline int read(){
    char ch=getchar();
    int res=0;
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
    return res;
} 
inline int lowbit(int x){
    return x&(-x);
}
const int N=100005;
tr1::unordered_map<int,int> mp[N];
int n,m,pos[N];
char ch;
inline void update(int x,int k,int add){
    while(x<=n){
        mp[x][k]+=add,x+=lowbit(x);
    }
}
inline int query(int x,int k){
    int res=0;
    while(x){
        res+=mp[x][k],x-=lowbit(x);
    }
    return res;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i){
        pos[i]=read(),update(i,pos[i],1);
    }
    for(int i=1;i<=m;++i){
        ch=getchar();
        while(ch!='Q'&&ch!='C')ch=getchar();
        int x=read(),y=read();
        if(ch=='Q'){
            int k=read();
            cout<<(query(y,k)-query(x-1,k))<<'\n';
        }
        else{
            update(x,y,1),update(x,pos[x],-1),pos[x]=y;
        }
    }
}
posted @ 2018-12-29 20:36  Stargazer_cykoi  阅读(100)  评论(0编辑  收藏  举报