比赛 2024暑假C班集训C 评测结果 TTTWTWTTTT
题目名称 灯笼 最终得分 0
用户昵称 ┭┮﹏┭┮ 运行时间 16.177 s
代码语言 C++ 内存使用 7.09 MiB
提交时间 2024-07-12 08:47:56
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define in inline 
#define re register
const int N = 2e5+10,M = N<<5;
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];
    int lowbit(int x){return x & (-x);}
    void add(int x,ll val){for(;x <= 3*n;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.find(a[i]) == cnt.end())sum++;
        cnt[a[i]]++;
        while(sum > m){
            t.add(s[l-1],-1);
            if(cnt[a[l]] == 1)sum--;
            cnt[a[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;
    
}