首页 > 其他分享 >Codeforces

Codeforces

时间:2022-08-14 10:24:01浏览次数:3308  
标签:int s2 ll Codeforces printf lld

Educational Codeforces Round 132 (Rated for Div. 2)

B

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a[N],s1[N],s2[N],l,r,n,m;
int main(){
    scanf("%lld%lld",&n,&m);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1;i<n;i++){
        if(a[i]<a[i+1]) s2[i]=a[i+1]-a[i];
        else s1[i]=a[i]-a[i+1];
    }
    for(ll i=1;i<n;i++){
        s1[i]=s1[i-1]+s1[i];
    }
    for(ll i=n-1;i;i--){
        s2[i]=s2[i+1]+s2[i];
    }
    for(ll i=1;i<=m;i++){
        scanf("%lld%lld",&l,&r);
        if(r>l) printf("%lld\n",s1[r-1]-s1[l-1]);
        else printf("%lld\n",s2[r]-s2[l]);
    }
    return 0;
}

CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)

B

#include <bits/stdc++.h>
using namespace std;
int t,n,m,a;
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m);
		int f=0,l=-1e9,r=1e9,ans=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&a);
			l=max(l, a-m);
			r=min(r, a+m);
			if(l>r){
				l=a-m;
				r=a+m;
				ans++;
			}
		}
		printf("%d\n",ans); 
	}
	return 0;
}

标签:int,s2,ll,Codeforces,printf,lld
From: https://www.cnblogs.com/xiaocaibiancheng/p/16584886.html

相关文章

  • Codeforces Round #813 (Div. 2)
    这一场打得很稀烂QwQ。开局先看A,开始秒想了一个假掉的做法,WA了3发,以后一定要先证明正确性再写。。。A写了16分钟。。。B很快在35分钟的时候秒掉了,C想到了一个暴力做法,......
  • Codeforces Round #813 (Div. 2) A~C
    A.WonderfulPermutation  Youaregivenapermutation p1,p2,…,pnp1,p2,…,pn oflength nn andapositiveinteger k≤nk≤n.Inoneoperationyoucanc......
  • Codeforces 121 E
    感觉我数据结构有些弱,最近开始练习难道为2300~2700的数据结构题。首先我们发现,luckynumber不会太多,最多就是\((2^1+2^2+2^3+2^4+1)=31\)个(最后加\(1\)是对于所有\(x>7777......