Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
1913 16级赵子潇 【S】T2 区间 C++ 解答错误 90 33 MS 6172 KB 1067 2020-11-16 21:31:50

Tests(9/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(); } } void print(const int &x){ if(x > 9) print(x / 10); putchar(x % 10 + '0'); } const int N = 1000010; int n, x, a, sum, ans; struct node{ int w, op, pos; }q[N]; int l; inline void pop(){ if(q[l].w == q[l - 1].w && q[l].op != q[l - 1].op) sum -= q[l - 1].pos - q[l - 2].pos; --l; } inline void push(int w, int op, int pos){ while(l && (q[l].w < w || (q[l].w == w && q[l].op == op))) pop(); if(q[l].w == w && q[l].op != op) sum += q[l].pos - q[l - 1].pos; q[++l] = (node){w, op, pos}; } int main() { read(n); read(x); for(int i = 1;i <= n;i++){ read(a); push(a, 1, i); push(x - a, 2, i); ans += sum; } print(ans); return 0; }


测评信息: