Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
1869 | 18级李灏冬 | 【S】T2 区间 | C++ | 解答错误 | 90 | 171 MS | 4124 KB | 1653 | 2020-11-16 16:34:29 |
#include<bits/stdc++.h> using namespace std; int n,x; int val; int ans; int sum; struct node{ int w; int col; int pos; }; node sta[1000005]; int top; int main(){ cin>>n>>x; for(int i=1;i<=n;i++){ scanf("%d",&val); while(top && sta[top].w<val){ if(top==1){ top=0; break; } if(sta[top].w==sta[top-1].w) sum-=sta[top-1].pos-sta[top-2].pos; top--; } while(sta[top].w==val && sta[top].col==1 && top){ if(top==1){ top=0; break; } if(sta[top].w==sta[top-1].w) sum-=sta[top-1].pos-sta[top-2].pos; top--; } sta[++top]=(node){val,1,i}; if(sta[top].w==sta[top-1].w) sum+=sta[top-1].pos-sta[top-2].pos; val=x-val; while(top && sta[top].w<val){ if(top==1){ top=0; break; } if(sta[top].w==sta[top-1].w) sum-=sta[top-1].pos-sta[top-2].pos; top--; } while(sta[top].w==val && sta[top].col==2 && top){ if(top==1){ top=0; break; } if(sta[top].w==sta[top-1].w) sum-=sta[top-1].pos-sta[top-2].pos; top--; } sta[++top]=(node){val,2,i}; if(sta[top].w==sta[top-1].w) sum+=sta[top-1].pos-sta[top-2].pos; ans+=sum; } cout<<ans<<endl; return 0; }