Solution
注意到 且 。
排列改变的次数不超过 ,那么改变的一定只有最后的 位。考虑维护前缀和暴力修改即可。
Code
/* ChongYun */
#include<bits/stdc++.h>
#define START_LL 1
using namespace std;
#define start(x) using namespace x
#if START_LL
#define int long long
#endif
namespace IO{
inline int read(){
register int x=0,f=1;
register char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void write(int x){
if(x<0) x=-x,putchar('-');
if(x>9) write(x/10);
putchar((x%10)^48);
return ;
}
}start(IO);
const int N=2e5+5;
int n,q,cnt=1;
int fac[N],sum[N];
bool vis[N];
signed main(){
n=read(); q=read();
fac[0]=1;
for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i;
for(int i=1;i<=n;++i) sum[i]=sum[i-1]+i;
while(q--){
int op=read();
if(op==1){
int l=read(),r=read();
write(sum[r]-sum[l-1]),putchar('\n');
}else{
cnt+=read();
int u=cnt;
int pos=max(1ll,n-13);
for(int i=pos;i<=n;++i) vis[i]=0;
for(int i=pos;i<=n;++i){
int now=0;
for(int j=pos;j<=n;++j){
if(vis[j]) continue;
if(now+fac[n-i]>=u){
u-=now,vis[j]=1;
sum[i]=sum[i-1]+j;
break;
}
else now+=fac[n-i];
}
}
}
}
return 0;
}