@KirinBill
2017-10-23T19:39:21.000000Z
字数 5663
阅读 1131
题解
套题
目录
#include <cstdio>
#include <cctype>
#include <string>
using std::string;
inline void setIO(string file){
string in=file+".in",out=file+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
template<typename type>
inline void read(type &x){
int pm=1; char c;
do{
c=getchar();
if(c=='-') pm=-1;
}while(!isdigit(c));
x=c^'0';
while(c=getchar(),isdigit(c))
x=x*10+(c^'0');
x*=pm;
}
template<typename type>
void write(type x,char c=0){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10|'0');
if(c) putchar(c);
}
#include <algorithm>
using std::max;
using std::sort;
using std::unique;
using std::lower_bound;
const int MAXN=200005;
int n,tot;
int crete[MAXN<<1];
struct node{
int pos,w;
bool operator< (const node &that)const{return pos<that.pos;}
}d[MAXN];
class valSegT{
#define ls (u<<1)
#define rs (ls|1)
private:
int sz[MAXN<<3];
int decrete(int x){
return lower_bound(crete+1,crete+tot+1,x)-crete;
}
void upd(int u){
sz[u]=max(sz[ls],sz[rs]);
}
int qry(int u,int l,int r,int lp,int rp){
if(lp<=l && r<=rp) return sz[u];
int mid=l+r>>1,ret=0;
if(lp<=mid) ret=qry(ls,l,mid,lp,rp);
if(rp>mid) ret=max(ret,qry(rs,mid+1,r,lp,rp));
return ret;
}
void ist(int u,int l,int r,int pos,int x){
if(l==r){
sz[u]=max(sz[u],x);
return;
}
int mid=l+r>>1;
if(pos<=mid) ist(ls,l,mid,pos,x);
else ist(rs,mid+1,r,pos,x);
upd(u);
}
public:
int qry(int rp){return qry(1,1,tot,1,decrete(rp));}
void ist(int pos,int x){ist(1,1,tot,decrete(pos),x);}
#undef ls
#undef rs
}T;
inline void decrete(){
sort(crete+1,crete+crete[0]+1);
tot=unique(crete+1,crete+crete[0]+1)-crete-1;
}
int main(){
setIO("clique");
read(n);
for(int i=1;i<=n;++i){
read(d[i].pos),read(d[i].w);
crete[++crete[0]]=d[i].pos-d[i].w;
crete[++crete[0]]=d[i].pos+d[i].w;
}
decrete();
sort(d+1,d+n+1);
int ans=0;
for(int i=1,tmp;i<=n;++i){
tmp=1+T.qry(d[i].pos-d[i].w);
ans=max(ans,tmp);
T.ist(d[i].pos+d[i].w,tmp);
}
write(ans);
return 0;
}
#include <cstdio>
#include <cctype>
#include <string>
using std::string;
inline void setIO(string file){
string in=file+".in",out=file+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
template<typename type>
inline void read(type &x){
int pm=1; char c;
do{
c=getchar();
if(c=='-') pm=-1;
}while(!isdigit(c));
x=c^'0';
while(c=getchar(),isdigit(c))
x=x*10+(c^'0');
x*=pm;
}
template<typename type>
void write(type x,char c=0){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10|'0');
if(c) putchar(c);
}
#include <algorithm>
using std::max;
const int MAXN=100005;
int n;
int a[MAXN];
class segT{
private:
struct node{
int l,r,ls,rs,max;
long long sum;
}d[MAXN<<2];
int new_nd(){
static int cnt=1;
return ++cnt;
}
void upd(int u){
int ls=d[u].ls,rs=d[u].rs;
d[u].max=max(d[ls].max,d[rs].max);
d[u].sum=d[ls].sum+d[rs].sum;
}
void mdf(int u,int pos,int x){
if(d[u].l==d[u].r){
d[u].sum=d[u].max=x;
return;
}
int mid=d[u].l+d[u].r>>1;
if(pos<=mid) mdf(d[u].ls,pos,x);
else mdf(d[u].rs,pos,x);
upd(u);
}
long long qry(int u,int lp,int rp){
if(lp<=d[u].l && d[u].r<=rp)
return d[u].sum;
int mid=d[u].l+d[u].r>>1;
long long ret=0;
if(lp<=mid) ret=qry(d[u].ls,lp,rp);
if(rp>mid) ret+=qry(d[u].rs,lp,rp);
return ret;
}
void mod(int u,int lp,int rp,int p){
if(d[u].max<p) return;
if(d[u].l==d[u].r){
d[u].max=d[u].sum=d[u].max%p;
return;
}
int mid=d[u].l+d[u].r>>1;
if(lp<=mid) mod(d[u].ls,lp,rp,p);
if(rp>mid) mod(d[u].rs,lp,rp,p);
upd(u);
}
void build(int u,int l,int r){
d[u].l=l,d[u].r=r;
if(l==r){
d[u].sum=d[u].max=a[l];
return;
}
int mid=l+r>>1;
d[u].ls=new_nd();
build(d[u].ls,l,mid);
d[u].rs=new_nd();
build(d[u].rs,mid+1,r);
upd(u);
}
public:
void build(){build(1,1,n);}
void mdf(int pos,int x){mdf(1,pos,x);}
long long qry(int lp,int rp){return qry(1,lp,rp);}
void mod(int lp,int rp,int p){mod(1,lp,rp,p);}
}T;
int main(){
setIO("mod");
int m;
read(n),read(m);
for(int i=1;i<=n;++i)
read(a[i]);
T.build();
for(int i=1,opt,a,b,c;i<=m;++i){
read(opt),read(a),read(b);
if(opt==1) write(T.qry(a,b),'\n');
else if(opt==3) T.mdf(a,b);
else{
read(c);
T.mod(a,b,c);
}
}
return 0;
}
#include <cstdio>
#include <climits>
const int MAXK=65;
int k;
long long m;
unsigned long long C_tab[MAXK][MAXK];
inline void pre_tab(){
C_tab[0][0]=1;
for(int i=1;i<=64;++i){
C_tab[i][0]=1;
for(int j=1;j<=i;++j)
C_tab[i][j]=C_tab[i-1][j-1]+C_tab[i-1][j];
}
}
inline unsigned long long C(int n,int m){
if(n<0 || m<0) return 0;
else return C_tab[n][m];
}
inline unsigned long long cal(unsigned long long x){
unsigned long long ret=0;
int cnt=0;
for(int i=63;i>=0;--i){
if(x&1ULL<<i){
ret+=C(i,k-cnt);
++cnt;
}
}
if(cnt==k) ++ret;
return ret;
}
inline long long bin_chop_l(){
unsigned long long l=1,r=LLONG_MAX,mid;
while(l<=r){
mid=l+r>>1;
if(cal(mid<<1)-cal(mid)>=m)
r=mid-1;
else l=mid+1;
}
return l;
}
inline long long bin_chop_r(){
unsigned long long l=1,r=LLONG_MAX,mid;
while(l<=r){
mid=l+r>>1;
if(cal(mid<<1)-cal(mid)<=m)
l=mid+1;
else r=mid-1;
}
return r;
}
int main(){
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
pre_tab();
int t;
scanf("%d",&t);
unsigned long long l,r;
for(int i=1;i<=t;++i){
scanf("%lld%d",&m,&k);
if(m==1 && k==1) puts("-1");
else{
l=bin_chop_l();
r=bin_chop_r();
printf("%lld %lld\n",l,r);
}
}
return 0;
}