# 【BestCoder #45】

T1

#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define maxn 10009
#define ll long long
using namespace std;
{
ll x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
ll n;
int main()
{
{
n=read(); int a=0, b=0;
while (n)
{
if (a==0 && (n&1)==1) b++;
a=n&1; n>>=1;
}
printf("%d\n", b);
}
return 0;
}

T2

#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define maxn 1009
#define maxq 100009
#define lowbit(x) (x&-x)
#define ll long long
using namespace std;
{
ll x=0, f=1; char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();
return x*f;
}
struct node{int x,y,z,w;} t[maxq];
int n, q, k[maxn], num[maxn], s[maxn];
bool cmp(node a, node b){return a.x<b.x;};
bool cmp2(node a, node b){return a.w<b.w;};
void Add(int x, int v)
{
while (x<=n) s[x]+=v, x+=lowbit(x);
}
int Que(int x)
{
int now=0;
while (x>0) now+=s[x], x-=lowbit(x);
return now;
}
int main()
{
rep(i, 1, n) k[i]=read();
rep(i, 1, q) t[i].x=read(), t[i].y=read(), t[i].w=i; sort(t+1, t+1+q, cmp);
rep(i, 1, n) rep(j, 1, i-1) if (k[j]>k[i]) num[i]++;
rep(i, 1, n) Add(i, num[i]);
int now=1;
rep(o, 1, q)
{
while (now<t[o].x)
{
rep(i, now+1, n) if (k[now]>k[i]) Add(i, -1);
now++;
}
t[o].z=Que(t[o].y);
}
sort(t+1, t+1+q, cmp2);
rep(i, 1, q) printf("%d\n", t[i].z);
return 0;
}

1001 Dylans loves numbers

1002 Dylans loves sequence
N只有1000，于是想怎么来就怎么来。

（可惜BC不给卡。。。呜呜呜）

1003 Dylans loves tree

（然而BC不给我卡log2。。。呜呜呜）

1004 Dylans loves polynomial
n的范围3000。考虑多项式插值的方法。

posted @ 2015-06-20 21:21  NanoApe  阅读(312)  评论(0编辑  收藏  举报