记录编号 |
590877 |
评测结果 |
AAAAAAAAAA |
题目名称 |
灯笼 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.809 s |
提交时间 |
2024-07-12 14:38:37 |
内存使用 |
7.89 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in inline
#define re register
const int N = 2e5+10;
const ll mod = 1e9+7;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m,X,len = 0;
ll a[N],s[N],c[N],b[N];
struct BIT{
ll c[N<<2];
int lowbit(int x){return x & (-x);}
void add(int x,ll val){for(;x <= 3e5;x += lowbit(x))c[x] += val;}
ll ask(int x){
if(x <= 0)return 0;
ll ans = 0;
for(;x > 0;x -= lowbit(x))ans += c[x];
return ans;
}
}t;
map<int,int>cnt;
int sum = 0;
ll ans = 0;
int main(){
freopen("lantern.in","r",stdin);
freopen("lantern.out","w",stdout);
n = read(),m = read(),X = read();
for(int i = 1;i <= n;i++)a[i] = read(),s[i] = s[i-1] + a[i],c[++len] = s[i],c[++len] = s[i] - X;
c[++len] = 0;
sort(c+1,c+1+len);
len = unique(c+1,c+1+len) - (c+1);
for(int i = 0;i <= n;i++){
b[i] = lower_bound(c+1,c+1+len,s[i] - X) - c;
s[i] = lower_bound(c+1,c+1+len,s[i]) - c;
}
int l = 1;
for(int i = 1;i <= n;i++){
if(cnt[a[i]] == 0)sum++;
cnt[a[i]] += 1;
while(sum > m){
t.add(s[l-1],-1);
if(cnt[a[l]] == 1)sum--;
cnt[a[l]] -= 1;
l++;///////////////////////////////////////////////////////////////////////
}
t.add(s[i-1],1);
ans += t.ask(b[i]) * 2ll;
if(a[i] >= X)ans--;
}
printf("%lld\n",ans);
return cerr<<clock()<<"ms"<<endl,0;
}