zoukankan      html  css  js  c++  java
  • 【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))<<'
    ';
            }
            else{
                update(x,y,1),update(x,pos[x],-1),pos[x]=y;
            }
        }
    }
    
  • 相关阅读:
    MyISAM 和 InnoDB 索引的区别
    iOS crash日志
    。。。
    redis的缓存测试
    job测试
    笔记
    Android获取启动页面Activity方法
    UI自动化框架-一个小demo
    mitmproxy-java 的尝试
    monkey
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/10366378.html
Copyright © 2011-2022 走看看