QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714519#5459. Goose, goose, DUCK?WzyRE 0ms3608kbC++141.9kb2024-11-05 23:51:562024-11-05 23:51:58

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 23:51:58]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-05 23:51:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<int,int> PII;
const int N=1e6+10,M=1e6+10;
const int mod=1e9+7;
int INF = 1e9;

int n, m;
struct Node
{
    int l, r;
    LL mn;
}tr[N * 4];

void pushup(int u)
{
    tr[u].mn = min(tr[u << 1].mn , tr[u << 1 | 1].mn);
}


void build(int u, int l, int r)
{
    if (l == r) tr[u] = {l, r, INF};
    else
    {
        tr[u] = {l, r};
        int mid = l + r >> 1;
        build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
        pushup(u);
    }
}

void modify(int u, int l, int r, int d)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        tr[u].mn = d;
    }
    else    // 一定要分裂
    {
        int mid = tr[u].l + tr[u].r >> 1;
        if (l <= mid) modify(u << 1, l, r, d);
        if (r > mid) modify(u << 1 | 1, l, r, d);
        pushup(u);
    }
}


 
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n),f(n+10);
    map<int,vector<int>> mp;
    map<PII,int> id;
    build(1,0,n-1);

    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=0;i<n;i++){
        mp[a[i]].push_back(i);
    }
    for(int i=0;i<n;i++) f[i]=-1;

    for(auto [x,y]:mp){
        for(int j=0;j<y.size();j++) id[{x,y[j]}]=j;

        if(y.size()<k) continue;

        for(int j=k-1;j<y.size();j++) f[y[j]]=max(f[y[j]],y[j-k+1]);
    }

    LL res=0;



    for(int i=0;i<n;i++){
        if(i) f[i]=max(f[i],f[i-1]);

        if(id.count({a[i],i})){
            int t=id[{a[i],i}];

            if(t>=k){
                modify(1,a[i],a[i],mp[a[i]][t-k]);
            }
        }

        if(tr[1].mn==INF) res+=f[i]+1;
        else res+=f[i]-tr[1].mn;
    }
    //cout<<endl;

    res=(LL)n*(n+1)/2-res;

    cout<<res<<endl;

}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) solve();
 
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Runtime Error

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:


result: