[CF707 Div2, A ~ D]

(相信进这个博客的人,都已经看过题目了,不再赘述)
这把打小号打到了\(484\),\(rating + 636\)

\(A\)

考虑进行模拟就行了,说白了这是一个英语阅读题

// code by Dix_
#include<bits/stdc++.h>
#define ll long long
 
inline ll read(){
    char C=getchar();
    ll N=0 , F=1;
    while(('0' > C || C > '9') && (C != '-')) C=getchar();
    if(C == '-') F=-1 , C=getchar();
    while('0' <= C && C <= '9') N=(N << 1)+(N << 3)+(C - 48) , C=getchar();
    return F*N;
}
 
ll T,a[200],b[200],t[200],now;
 
int main(){
	scanf("%lld",&T);
	while(T -- ){
		ll n;
		scanf("%lld",&n);
		for(int i = 1;i <= n;++i){
			scanf("%lld%lld",&a[i],&b[i]);
		}
		for(int i = 1;i <= n;++i)
		scanf("%lld",&t[i]);
		ll now = t[1] + a[1];
		for(int i = 1;i <= n - 1;++i){
			now += std::ceil(((double)b[i] - a[i]) / 2.0);
			now = std::max(now,b[i]);
			now += (a[i + 1] - b[i] + t[i + 1]);
		}
		std::cout<<now<<std::endl;
	}
}

\(B\)

考虑进行一个差分处理,再还原原数组

// code by Dix_
#include<bits/stdc++.h>
#define ll long long
 
inline ll read(){
    char C=getchar();
    ll N=0 , F=1;
    while(('0' > C || C > '9') && (C != '-')) C=getchar();
    if(C == '-') F=-1 , C=getchar();
    while('0' <= C && C <= '9') N=(N << 1)+(N << 3)+(C - 48) , C=getchar();
    return F*N;
}
 
ll t,cnt[200010],now;
 
int main(){
	scanf("%lld",&t);
	while(t -- ){
		ll n;
		scanf("%lld",&n);
		for(int i = 0;i <= n + 1;++i)
		cnt[i] = 0;
		for(int i = 1;i <= n;++i){
			ll x = read();
			cnt[i + 1] -= 1;
			cnt[std::max((ll)0,i - x + 1)] += 1;
		}
		for(int i = 1;i <= n;++i){
			cnt[i] = cnt[i - 1] + cnt[i];
			if(cnt[i])
			std::cout<<1<<" ";
			else
			std::cout<<0<<" ";
		}
		puts("");
	}
}

\(C\)

大毒瘤题,想了\(1h\)的做法最后和暴力一样写
观察\(n\)的范围和值域,我们发现在\(n\)较大时,点对数\((n * (n - 1)) / 2 > 2 * |V|\),所以必定有解,那么我们利用这个来进行一个抽屉原理证明
可以证明暴力写法复杂度是对的

// code by Dix_
#include<bits/stdc++.h>
#define ll long long
 
inline ll read(){
    char C=getchar();
    ll N=0 , F=1;
    while(('0' > C || C > '9') && (C != '-')) C=getchar();
    if(C == '-') F=-1 , C=getchar();
    while('0' <= C && C <= '9') N=(N << 1)+(N << 3)+(C - 48) , C=getchar();
    return F*N;
}
 
ll n;
std::map<ll,int>QWQ;
std::map<ll,int>QAQ;
ll num[200005];
 
int main(){
	scanf("%lld",&n);
	for(int i = 1;i <= n;++i)
	scanf("%lld",&num[i]);
	for(int i = 1;i <= n;++i)
	for(int j = i + 1;j <= n;++j){
		ll sum = num[i] + num[j];
        if(QWQ.count(sum))
        if(QWQ[sum] != i && QAQ[sum] != j && QWQ[sum] != j && QAQ[sum] != i){
			puts("YES");
			std::cout<<QWQ[sum]<<" "<<QAQ[sum]<<" "<<i<<" "<<j<<std::endl;
			return 0;
		}
		QWQ[sum] = i,QAQ[sum] = j;
	}
	puts("NO");
}

\(D\)

考虑一个周期内有多少个不同的,再二分求出后面零散的天数
\(Excrt\)不会,得去学,这题是后来补的

#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int N=1e6+5;

LL muler(LL x,LL k,LL MOD)
{
	LL res=0; x=(x%MOD+MOD)%MOD; k=(k%MOD+MOD)%MOD; 
	while(k) {
		if(k&1) res=(res+x)%MOD;
		x=(x+x)%MOD; k>>=1;
	}
	return res%MOD;
}

LL power(LL x,LL k,LL MOD)
{
	LL res=1; x%=MOD;
	while(k) {
		if(k&1) res=muler(res,x,MOD);
		x=muler(x,x,MOD); k>>=1;
	}
	return res%MOD;
}

LL exgcd(LL a,LL b,LL& x,LL& y)
{
	if(b==0) {
		x=1; y=0;
		return a;	
	}
	LL z=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return z;
}

LL inv(LL x,LL p) 
{
	LL y,z; exgcd(x,p,y,z);
	return (y%p+p)%p;  
}

LL excrt(int n,LL b[],LL a[])
{
	LL m=a[1],ans=b[1];
	for(int i=2;i<=n;i++) {
		LL y,z,d=exgcd(m,a[i],y,z);
		if((b[i]-ans)%d!=0) return -1;
		y=muler(y,(b[i]-ans)/d,a[i]/d);
		
		ans+=y*m;
		m=a[i]/d*m;
		ans=(ans%m+m)%m;
	}
	return ans;
}

LL gcd(LL a,LL b) 
{
	if(b==0) return a;
	else return gcd(b,a%b);
}

LL lcm(LL a,LL b) { return a/gcd(a,b)*b; }

int n,m;
LL kth;
int a[N],b[N],c[N];
LL A[N],B[N];
vector<LL> v;

LL calc(LL day) 
{
//	cerr<<day<<" "<<day-(upper_bound(v.begin(),v.end(),day)-v.begin())<<endl;
	if(day<=0) return 0;
	else return day-(upper_bound(v.begin(),v.end(),day)-v.begin());
}

int main()
{
//	freopen("1.in","r",stdin);
	int i,j;
	LL x;
	
	scanf("%d%d%lld",&n,&m,&kth);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	for(i=0;i<m;i++) scanf("%d",&b[i]);
	memset(c,-1,sizeof c);
	for(i=0;i<n;i++) c[a[i]]=i;
	for(i=0;i<m;i++) {
		if(~c[b[i]]) {
			j=c[b[i]];
			A[1]=n; A[2]=m;
			B[1]=j; B[2]=i;
			x=excrt(2,B,A);
			if(x==-1) continue;
			v.push_back(x+1);
//			cerr<<x<<endl;
		}
	}
	sort(v.begin(),v.end());
	LL times=lcm(n,m)-v.size();
	LL turns=(kth-1)/times;
	kth-=turns*times;
	
	LL L=-1,R=lcm(n,m),mid;
	while(L+1<R) {
		mid=(L+R)>>1;
		if(calc(mid)>=kth) R=mid;
		else L=mid;
	}
	printf("%lld\n",turns*lcm(n,m)+R);
	return 0;
}
posted @ 2021-03-15 11:23  fhq_treap  阅读(69)  评论(0编辑  收藏  举报