Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
1826 16级赵子潇 【S】T2 区间 C++ 运行超时 60 2005 MS 13936 KB 1107 2020-11-16 10:57:52

Tests(6/10):


#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; inline char getc(){ return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x){ x = 0; char s = getc(); while(s < '0' || s > '9') s = getc(); while('0' <= s && s <= '9'){ x = (x << 3) + (x << 1) + (s ^ 48); s = getc(); } } const int N = 1000010; int n, x, a[N], res; int g[N], l[N], r[N]; // g[i]表示值>=i出现的最晚的位置 int main() { read(n); read(x); for(int i = 1;i <= n;i++) read(a[i]); for(int i = 1;i <= n;i++){ // a[i]作为第一个max int Max = a[i], Min = x - a[i]; l[i] = r[i] = i; while(l[i] > 1 && a[l[i] - 1] < Max && a[l[i] - 1] >= Min) --l[i]; while(r[i] < n && a[r[i] + 1] <= Max && a[r[i] + 1] >= Min) ++r[i]; int ans = (i - l[i] + 1) * (r[i] - i + 1); if(a[i] != Min){ int L = i, R = i; while(L > l[i] && a[L - 1] != Min) --L; while(R < r[i] && a[R + 1] != Min) ++R; ans -= (i - L + 1) * (R - i + 1); } res += ans; } cout << res; return 0; }


测评信息: