Testing Round #12

来源:互联网 发布:现在最红网络的游戏 编辑:程序博客网 时间:2024/05/29 07:38
A. Divisibility

Find the number of k-divisible numbers on the segment[a, b]. In other words you need to find the number of such integer valuesx that a ≤ x ≤ b andx is divisible by k.

Input

The only line contains three space-separated integers k,a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Sample test(s)
Input
1 1 10
Output
10
Input
2 -4 4
Output
5题解: 简单水题AC代码:
/* ***********************************************Author        :xdloveCreated Time  :2015年11月12日 星期四 10时28分42秒File Name     :xdlove/codeforces/Testing_Round_#12/A/A.cpp************************************************ */#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <memory.h>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define REP_ab(i,a,b) for(int i = a; i <= b; i++)#define REP(i, n) for(int i = 0; i < n; i++)#define REP_1(i,n) for(int i = 1; i <= n; i++)#define DEP(i,n) for(int i = n - 1; i >= 0; i--)#define DEP_N(i,n) for(int i = n; i >= 1; i--)#define CPY(A,B) memcpy(A,B,sizeof(B))#define MEM(A) memset(A,0,sizeof(A))#define MEM_1(A) memset(A,-1,sizeof(A))#define MEM_INF(A) memset(A,0x3f,sizeof(A))#define MEM_INFLL(A) memset(A,0x3f3f,sizeof(A))#define mid (((l + r) >> 1))#define lson l, mid, u << 1#define rson mid + 1, r, u << 1 | 1#define ls (u << 1)#define rs (u << 1 | 1)typedef long long ll;typedef unsigned long long ull;const int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3f;const int MAXN = 1e5 + 5;const int MAXM = MAXN;const int mod = 1e9 + 7;int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    ll k,a,b,ans = 0;    cin>>k>>a>>b;    if(a == b && a == 0) ans = 1;    else     {        if(b >= 0)         {            ans += b / k;            if(a > 0) ans -= (a - 1) / k;            else ans += -a / k + 1;        }        else             ans += -a / k - (-b - 1) / k;    }    cout<<ans<<endl;    return 0;}


B. Restaurant

A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Sample test(s)
Input
27 114 7
Output
1
Input
51 22 33 44 55 6
Output
3
Input
64 81 54 72 51 36 8
Output
2题解: 简单水题AC代码:
/* ***********************************************Author        :xdloveCreated Time  :2015年11月12日 星期四 10时39分50秒File Name     :xdlove/codeforces/Testing_Round_#12/B/B.cpp************************************************ */#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <memory.h>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define REP_ab(i,a,b) for(int i = a; i <= b; i++)#define REP(i, n) for(int i = 0; i < n; i++)#define REP_1(i,n) for(int i = 1; i <= n; i++)#define DEP(i,n) for(int i = n - 1; i >= 0; i--)#define DEP_N(i,n) for(int i = n; i >= 1; i--)#define CPY(A,B) memcpy(A,B,sizeof(B))#define MEM(A) memset(A,0,sizeof(A))#define MEM_1(A) memset(A,-1,sizeof(A))#define MEM_INF(A) memset(A,0x3f,sizeof(A))#define MEM_INFLL(A) memset(A,0x3f3f,sizeof(A))#define mid (((l + r) >> 1))#define lson l, mid, u << 1#define rson mid + 1, r, u << 1 | 1#define ls (u << 1)#define rs (u << 1 | 1)typedef long long ll;typedef unsigned long long ull;const int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3f;const int MAXN = 5e5 + 5;const int MAXM = MAXN;const int mod = 1e9 + 7;struct RE{    int l,r;    void in()    {        scanf("%d %d",&l,&r);    }    bool operator < (const RE &a) const    {        return r < a.r;    }}p[MAXN];int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    int n;    cin>>n;    REP(i,n) p[i].in();    sort(p,p + n);    int num = 1,pos = p[0].r;    REP_1(i,n - 1)    {        if(p[i].l > pos)        {            num++;            pos = p[i].r;        }    }    cout<<num<<endl;    return 0;}

C. Subsequences

For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.

Input

First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.

Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.

Output

Print one integer — the answer to the problem.

Sample test(s)
Input
5 212354
Output
7题解:       很好的一道用数据结构来优化DP的一道题,首先很容易想到DP的状态转移方程,以dp[i][j]表示前i个数以a[i]结尾的递增序列长度为j的方案数,则状态的转移方程就可以写为 dp[i][j] += dp[x][j - 1],其中满足a[x]<a[i];这部分的处理如果不用数据结构优化,时间复杂度是n^2的,因为注意到我们是统计所有小于a[i]的DP值的和,所以可以利用树状数组或者线段树优化;AC代码:
/* ***********************************************Author        :xdloveCreated Time  :2015年11月12日 星期四 10时49分32秒File Name     :xdlove/codeforces/Testing_Round_#12/C/c.cpp************************************************ */#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <memory.h>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define REP_ab(i,a,b) for(int i = a; i <= b; i++)#define REP(i, n) for(int i = 0; i < n; i++)#define REP_1(i,n) for(int i = 1; i <= n; i++)#define DEP(i,n) for(int i = n - 1; i >= 0; i--)#define DEP_N(i,n) for(int i = n; i >= 1; i--)#define CPY(A,B) memcpy(A,B,sizeof(B))#define MEM(A) memset(A,0,sizeof(A))#define MEM_1(A) memset(A,-1,sizeof(A))#define MEM_INF(A) memset(A,0x3f,sizeof(A))#define MEM_INFLL(A) memset(A,0x3f3f,sizeof(A))#define mid (((l + r) >> 1))#define lson l, mid, u << 1#define rson mid + 1, r, u << 1 | 1#define ls (u << 1)#define rs (u << 1 | 1)typedef long long ll;typedef unsigned long long ull;const int INF = 0x3f3f3f3f;const ll INFLL = 0x3f3f3f3f3f3f3f3f;const int MAXN = 1e5 + 5;const int MAXM = MAXN;const int mod = 1e9 + 7;int n,k;ll dp[MAXN][20],val[20][MAXN];int lowbit(int x){    return x & -x;}void add(ll c,ll b[],int v){    while(v <= n)    {        b[v] += c;        v += lowbit(v);    }}ll sum(ll b[],int v){    ll s = 0;    while(v > 0)    {        s += b[v];        v -= lowbit(v);    }    return s;}int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    cin>>n>>k;    k++;    REP_1(i,n)    {        int x;        scanf("%d",&x);        dp[i][1] = 1;        REP_1(j,k)        {            if(j > i) break;            ll tp = sum(val[j - 1],x - 1);            dp[i][j] += tp;            add(dp[i][j],val[j],x);        }    }    ll ans = 0;    REP_1(i,n) ans += dp[i][k];    cout<<ans<<endl;    return 0;}



0 0
原创粉丝点击