SDUT 2017 Autumn Single Contest N 模板场

Let’s consider an infinite sequence of digits constructed of ascending powers of 10 written one after another. Here is the beginning of the sequence: 110100100010000… You are to find out what digit is located at the definite position of the sequence.
Input
There is the only integer N in the first line (1 ≤ N ≤ 65535). The i-th of N left lines contains the integer Ki — the number of position in the sequence (1 ≤ Ki ≤ 2 31 − 1) .
Output
You are to output N digits 0 or 1 separated with a space. More precisely, the i-th digit of output is to be equal to the Ki-th digit of described above sequence.

询问题目所示
1 10 100 1000的数列的第n项是什么结果

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    int t;
    long long n;
    cin>>t;
    int top = 1;
    set<long long>o;
    o.insert(1);
    for(long long i=1;(i*(i+1))/2<=(1LL<<32);i++)
    {
        o.insert(((i+1)*i/2)+1);
    }
    while(t--)
    {
        cin>>n;
        if(o.count(n))
        {
            if(top)top = 0;
            else cout<<" ";
            cout<<"1";
        }
        else
        {
            if(top)top = 0;
            else cout<<" ";
            cout<<"0";
        }

    }
    return 0;
}

B - Primes on Interval CodeForces - 237C
You’ve decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.

Consider positive integers a, a + 1, …, b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x (a ≤ x ≤ b - l + 1) among l integers x, x + 1, …, x + l - 1 there are at least k prime numbers.

Find and print the required minimum l. If no value l meets the described limitations, print -1.

Input
A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 106; a ≤ b).

Output
In a single line print a single integer — the required minimum l. If there’s no solution, print -1.

Example
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1

素数筛+前缀和+二分

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1999999;
bool nsu[1999999]= {0};
int pre[maxn]= {0};
void qiu_prime()
{
    nsu[1] = true;
    for(int i=2; i<maxn; i++)
    {
        if(nsu[i])continue;
        for(int j=i*2; j<maxn; j+=i)
        {
            nsu[j] = true;
        }
    }
}
int k,a,b;
bool pan(int l)
{
    for (int i = a; i <= b - l + 1; i++)
    {
        if (pre[i + l - 1] - pre[i - 1] < k) return false;
    }
    return true;
}
int main()
{
    qiu_prime();
    //memset(pre,0,sizeof(pre));
    cin>>a>>b>>k;
    for(int i=1; i<=maxn; i++)
    {
        pre[i]+=pre[i-1];
        if(!nsu[i])pre[i]+=1;
    }
    int l = 1, r = b - a + 1;
    int ans = -1;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        //cout<<mid<<endl;
        if (pan(mid))
        {
            ans = mid;
            //cout<<ans<<"*"<<endl;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

C 线段树模板题
Tired of playing computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do some multiplication in a number sequence. After playing it a few times, he has found it is also too boring. So he plan to do a more challenge job: he wants to change several numbers in this sequence and also work out the multiplication of all the number in a subsequence of the whole sequence.
To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he…

Input
The first line is the number of case T (T<=10).
For each test case, the first line is the length of sequence n (n<=50000), the second line has n numbers, they are the initial n numbers of the sequence a1,a2, …,an,
Then the third line is the number of operation q (q<=50000), from the fourth line to the q+3 line are the description of the q operations. They are the one of the two forms:
0 k1 k2; you need to work out the multiplication of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n)
1 k p; the kth number of the sequence has been change to p. (1<=k<=n)
You can assume that all the numbers before and after the replacement are no larger than 1 million.
Output
For each of the first operation, you need to output the answer of multiplication in each line, because the answer can be very large, so can only output the answer after mod 1000000007.
Sample Input
1
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
Sample Output
240
420

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 50000+7;
const int mod = 1e9+7;
#define  ll long long
#define MID int mid = (l+r)/2;
ll tree[maxn<<3],a[maxn<<1];
#define lson root<<1
#define rson root<<1|1
int n;
void build(int root,int l,int r)
{
    if(l==r)
    {
        tree[root] = a[l];
        return ;
    }
    MID
    build(lson,l,mid);
    build(rson,mid+1,r);
    tree[root]  = tree[lson]*tree[rson]%mod;
}
void update(int root,int l,int r,int pos,ll x)
{
    if(pos<l||pos>r)return ;
    if(l==r)
    {
        tree[root] = x;
        return;
    }
    MID
    update(lson,l,mid,pos,x);
    update(rson,mid+1,r,pos,x);
     tree[root]  = tree[lson]*tree[rson]%mod;
}
ll query(int root,int l,int r,int a,int b)
{
    if(b<l||a>r)return 1;
    if(a<=l&&r<=b)return tree[root];
    MID
    return (query(lson,l,mid,a,b)*query(rson,mid+1,r,a,b))%mod;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
        build(1,1,n);
        int q;
        cin>>q;
        while(q--)
        {
            ll a,b,c;
            scanf("%lld%lld%lld",&a,&b,&c);
            if(a)
            {
                update(1,1, n,b,c);
            }
            else
            {
                cout<<query(1,1,n,b,c)<<endl;
            }
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值