19-10-31-B

%%%B

ZJ一下:

开题。

发现

语文考试????

我不认识XD。老帅哥救我!

后来……

对什么取模???

什么玩意??输入什么??

满足啥??

全是亻

啊!

后来才知道是题楔×了

不管了。

然后发现T1是慢速乘?

我以为是自然数幂和,结果不是。

就一个柿子。

T2想了半天……后来丢一个 set 乱搞。

T3打暴力,后来没调出来……

这是TJ:

T1

慢速乘(=快速加$\Leftarrow$快速幂)

直接等差数列求和。

//sum

#include <iostream>
#include <cstring>
#include <cstdio>
#define LL long long

using namespace std;

LL lx,ly,rx,ry,mod;
LL li,co;
LL mul(LL a,LL b){
	LL res=0;
	a%=mod;
	while(b){
		if(b&1)res=(res+a)%mod;
		a=(a+a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
#ifndef LOCAL
	freopen("sum.in" ,"r",stdin);
	freopen("sum.out","w",stdout);
#endif
	cin>>lx>>ly>>rx>>ry>>mod;
	li=rx-lx+1;
	co=ry-ly+1;
	LL ans=0;
	if(co&1) ans=(ans+mul(mul((co+1)/2,  co),li))%mod;
	else     ans=(ans+mul(mul( co+1   ,co/2),li))%mod;
	if(li&1) ans=(ans+mul(mul((li-1)/2,li  ),co))%mod;
	else     ans=(ans+mul(mul( li-1   ,li/2),co))%mod;
	LL val=((lx%mod+ly%mod)%mod-2+mod)%mod;
	ans=(ans+mul(mul(li,co),val))%mod;
	cout<<ans<<endl;
}

T2

倍增。

这个题是倍增思想的普适思路。

区间合法就先更新,然后将增量倍增。

区间非法就不更新,然后将增量减半。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 555555
#define LL long long

using namespace std;

LL lim;
int pn;
LL bo[N],gi[N];
int ans=0;
vector<LL>a,b;
LL check(int l,int r){
	a.clear();
	b.clear();
	for(int i=l;i<=r;i++){
		a.push_back(bo[i]);
		b.push_back(gi[i]);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	LL dat=0;
	for(int i=0;i<a.size();i++){
		dat+=a[i]*b[i];
	}
//	cout<<l<<" "<<r<<" "<<dat<<endl;
	return dat;
}
int main(){
#ifndef LOCAL
	freopen("pair.in" ,"r",stdin);
	freopen("pair.out","w",stdout);
#endif
	cin.sync_with_stdio(false);
	cin>>pn>>lim;
	for(int i=1;i<=pn;i++)
		cin>>bo[i];
	for(int i=1;i<=pn;i++)
		cin>>gi[i];
	for(int i=1;i<=pn;){
		int p=1,r=i;
		ans++;
		while(p!=0){
			if(r+p<=pn&&check(i,r+p)<=lim){
				r+=p;
				p*=2;
			}
			else p/=2;
		}
		i=r+1;
	}
	cout<<ans<<endl;
}

T3

 先口古

posted @ 2019-10-31 22:00  Miemeng_麦蒙  阅读(175)  评论(2编辑  收藏  举报

小麦在雨中,蒙蒙的雾气

麦蒙不想有人骚扰他,如果有必要 联系 QQ:1755601414

如果你嫌广告大,那就喷我吧,不是博客园的锅。