QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714520#5459. Goose, goose, DUCK?WzyWA 12ms37612kbC++141.9kb2024-11-05 23:53:372024-11-05 23:53:38

Judging History

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

  • [2024-11-05 23:53:38]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:37612kb
  • [2024-11-05 23:53:37]
  • 提交

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,1,1e6);

    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: 8ms
memory: 37456kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 12ms
memory: 37612kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 37604kb

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:

3889

result:

wrong answer 1st numbers differ - expected: '4309', found: '3889'