noip2019集训测试赛(二)

Problem A: 余数

Time Limit: 1000 ms Memory Limit: 512 MB

Description

Input

Output

Sample Input
3 4
Sample Output
4

HINT

Solution

那个所谓\(\sqrt n\)的东西叫做整除分块。

显然对于\(n÷i\),当$i<=\sqrt n $时,每个i都有一种取法

\(n>=i>\sqrt n\),i每加\(\sqrt n\)\(n÷i\)的值就+1

然后就可以根号时间复杂度求了。

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
const unsigned long long inv2=5e8+4;
unsigned long long n,m,ans=0;
signed main(){
    scanf("%llu%llu",&n,&m);
    for(unsigned long long i=1,pos;i<=min(n,m);i=pos+1){
        pos=min((n/(n/i)),m);
        (ans+=n%mod*((pos-i+1)%mod)%mod-(i+pos)%mod*((pos-i+1)%mod)%mod*inv2%mod*((n/i)%mod)%mod+mod)%=mod;
    }
    if(m>n)(ans+=n%mod*((m-n)%mod)%mod)%=mod;
    printf("%llu\n",ans%mod);
}

Problem B: 糖果

Time Limit: 1000 ms Memory Limit: 512 MB

Description

Input

Output

Sample Input
5
8 7 4 8 3
4 2 5 3 7
Sample Output
3
1 4 5

HINT

Solution

把糖果们按照a值从大到小排序,然后先取第一个出来,之后的两两分组,每组取b值较大的一个

易证这样是满足要求的(是因为我不会严谨证明)

#include<bits/stdc++.h>
using namespace std;
int n;
struct qwq{
    int a,b;
    int id;
}a[200001];
bool cmp(qwq a,qwq b){
    return a.a>b.a;
}
bool vis[200001];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i].a);
    }
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i].b);
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=2;i<=n;i+=2){
        if(a[i].b>a[i+1].b)vis[i]=true;
        else vis[i+1]=true;
    }
    printf("%d\n",(n/2)+1);
    printf("%d ",a[1].id);
    for(int i=2;i<=n;++i){
        if(vis[i])printf("%d ",a[i].id);
    }
}

Problem C: 虫子

Time Limit: 2000 ms Memory Limit: 512 MB

Description

Input

Output

Sample Input
5
1 2 2 1
1 2 3 4 5
5
1 3 4
1 4 5
2 2 3
1 5 2
1 1 4
Sample Output
1.64
1.80
2.28
2.32
2.80
1.84

HINT

Solution

还不会,等我学了树剖再说。

猜你喜欢

转载自www.cnblogs.com/youddjxd/p/11329556.html
今日推荐