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