跳到正文

剪贴板

剪贴板 a6hapbsd

原文
剪贴板信息

剪贴板信息

收录
更新
C++
/*
* 伞也不打地走向明天
* written by ღꦿ࿐
 */

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define Rep(i,x,y) for(int i=x;i>=y;--i)
namespace io {
    char buf[(1<<20)+5],*p1,*p2;
    #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
    int read(){
        int f=0,x=0;
        char ch=getchar();
        while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
        while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
        return f?-x:x;
    }
}
using namespace std;
using io::read;
using ll = long long ;
const int M = 1e6 + 5e5 + 20 ;
const int N = 1e5 + 20 ;
int n  , m ;
int sl[M] , sr[M] , bel[M] , tot ;
int pre[N] , now[N] , cnt[N] , pt[N];
bitset < N > h ;
bitset < M > vis ;
vector <int> pl[N] , cg;
namespace bit {
    int t[N] ;
    void upd (int x,int c) {
        for(x ++; x < N ; x += x & -x) t[x] += c ;
    }
    int qry (int x,int c = 0) {
        for(x ++ ; x ; x &= x - 1) c += t[x] ;
        return c ;
    }
}
namespace sgt  {
    int mncg[N << 2];
    #define ls x<<1
    #define rs x<<1|1
    #define mid ((l+r)>>1)
    void mtn (int x) {
        mncg[x] = min(mncg[ls] , mncg[rs]) ;
    }
    void build(int x,int l,int r) {
        if(l == r) {
            if(pt[l] < pl[l].size( )) mncg[x] = sr[pl[l][pt[l]]] ;
            else mncg[x] = 0;
            return ;
        }
        build(ls,l,mid) ; build(rs,mid+1,r) ; mtn(x) ;
    }
    void beats(int x,int l,int r,int p) {
        if(p < l || p > mncg[x]) return ;
        if(l == r) {
            while(pt[l] < pl[l].size( ) && p <= sr[pl[l][pt[l]]]) vis[pl[l][pt[l]]] = 1 , cg.emplace_back(bel[pl[l][pt[l]]]) , pt[l] ++ ;
            if(pt[l] < pl[l].size( )) mncg[x] = sr[pl[l][pt[l]]] ;
            else mncg[x] = 0;
            return ;
        }
        beats(ls,l,mid,p) ;
        beats(rs,mid+1,r,p) ;
        mtn(x);
    }
}
int op , x , y , res ;
bool cmp (int x,int y) {
    return sr[x] > sr[y];
}
signed main ( ) {
    n = read( ) , m = read( ) ;
    rep(d,1,n) {
        now[d] = 1 ;
        cnt[d] = (n + d - 1) / d ;
        rep(i,1,cnt[d]) {
            ++ tot ;
            sl[tot] = (i - 1) * d + 1;
            sr[tot] = min(n , i * d);
            bel[tot] = d ;
            pl[sl[tot]].emplace_back(tot) ;
        }
        pre[d + 1] = tot  ;
    }
    rep(i,1,n) {
        sort(pl[i].begin ( ) , pl[i].end( ) , cmp) ;
    }
    sgt::build(1,1,n) ;
    while(m --) {
        op = read( ) ;
        if(op == 1) {
            x = read( ) ;
            if(h[x]) continue;
            h[x] = 1;
            sgt::beats(1,1,n,x) ;
            for(int d:cg) {
                while(now[d] <= cnt[d] && vis[pre[d] + now[d]]) bit::upd(d,1) , now[d] ++ ;
            }
            cg.clear( ) ;
        }
        else {
            x = read( ) , y = read( ) ;
            res = bit::qry(y) - bit::qry(x - 1) + (y - x + 1) ;
            printf( "%d\n" , res ) ;
        }
    }
}