Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
1851 | 16级钟煜奇 | 【S】T2 区间 | C++ | 解答错误 | 60 | 172 MS | 23504 KB | 1055 | 2020-11-16 15:01:18 |
#include <iostream> #include <cstdio> #define int long long #define fi first #define se second using namespace std; const int MAX=1e6+5; struct node{ int value,pos,color; //0 ai 1 x-ai }sta[MAX<<1]; int tp; int a[MAX]; int n,x,sum,ans; signed main(){ scanf("%lld %lld",&n,&x); sta[0].color=-1; for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); while(tp && sta[tp].value<a[i]){ if(tp>1 && sta[tp].value==sta[tp-1].value && sta[tp].color!=sta[tp-1].color)sum-=(sta[tp-1].pos-sta[tp-2].pos); tp--; } sta[++tp]=node{a[i],i,0}; if(tp>1 && sta[tp].value==sta[tp-1].value && sta[tp].color!=sta[tp-1].color)sum+=(sta[tp-1].pos-sta[tp-2].pos); while(tp && sta[tp].value<x-a[i]){ if(tp>1 && sta[tp].value==sta[tp-1].value && sta[tp].color!=sta[tp-1].color)sum-=(sta[tp-1].pos-sta[tp-2].pos); tp--; } sta[++tp]=node{x-a[i],i,1}; if(tp>1 && sta[tp].value==sta[tp-1].value && sta[tp].color!=sta[tp-1].color)sum+=(sta[tp-1].pos-sta[tp-2].pos); ans+=sum; } printf("%lld",ans); return 0; }