QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721534#9584. 顾影自怜mojo__hugoWA 58ms26756kbC++201.4kb2024-11-07 16:19:472024-11-07 16:19:47

Judging History

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

  • [2024-11-07 16:19:47]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:26756kb
  • [2024-11-07 16:19:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
using PII=pair<int,int>;

const int N=1e6+5;

int a[N],l[N],r[N],idx[N];
vector<int>id[N];
void solve(){
    int n,k;
    cin>>n>>k;
    ll ans=0;
    vector<int>stk;
    for(int i=1;i<=n;i++)id[i].clear();
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        idx[i]=id[a[i]].size();
        id[a[i]].push_back(i);
        while(stk.size()&&a[stk.back()]<a[i])
            stk.pop_back();
        if(stk.size())
            l[i] = stk.back();
        else
            l[i] = 0;
        
        stk.push_back(i);
        l[i]++;
    }
    stk.clear();
    for (int i = n; i >= 1;i--){
        while(stk.size()&&a[stk.back()]<=a[i])
            stk.pop_back();
        if(stk.size())
            r[i] = stk.back();
        else
            r[i] = n + 1;
        stk.push_back(i);
        r[i]--;
    }
    for (int i = 1; i <= n;i++){
        if(idx[i]+k<=id[a[i]].size()){
            int tmp=id[a[i]][idx[i]+k-1];
            if(idx[i]+k+1<=id[a[i]].size()){
                r[i]=min(r[i],id[a[i]][idx[i]+k]-1);
            }
            ans+=1ll*l[i]*(r[i]-tmp+1);
            // cout << l[i] << ' ' << r[i] <<' '<<tmp<< endl;
        }
        
    }
    cout<<ans<<endl;
}

signed main(){
    // freopen("data.in","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11812kb

input:

2
5 2
1 3 3 2 2
4 3
1 4 2 1

output:

7
0

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 32ms
memory: 26756kb

input:

1
1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

500000500000

result:

ok single line: '500000500000'

Test #3:

score: -100
Wrong Answer
time: 58ms
memory: 12008kb

input:

158921
1 1
1
2 1
1 1
2 2
1 1
2 1
1 2
2 2
1 2
2 1
2 1
2 2
2 1
2 1
2 2
2 2
2 2
3 1
1 1 1
3 2
1 1 1
3 3
1 1 1
3 1
1 1 2
3 2
1 1 2
3 3
1 1 2
3 1
1 1 3
3 2
1 1 3
3 3
1 1 3
3 1
1 2 1
3 2
1 2 1
3 3
1 2 1
3 1
1 2 2
3 2
1 2 2
3 3
1 2 2
3 1
1 2 3
3 2
1 2 3
3 3
1 2 3
3 1
1 3 1
3 2
1 3 1
3 3
1 3 1
3 1
1 3 2
3 2...

output:

1
3
1
2
0
4
0
3
1
6
3
1
4
1
0
4
1
0
6
-1
0
5
1
0
3
0
0
6
-1
0
6
0
0
5
1
0
8
2
0
6
1
0
5
0
0
8
2
0
6
3
1
4
1
0
6
0
0
6
-1
0
5
1
0
8
2
0
7
0
0
6
1
0
10
0
0
8
2
0
6
1
0
8
2
0
8
2
0
6
3
1
10
6
3
1
7
3
1
0
7
3
1
0
7
3
1
0
9
-1
-1
0
8
2
0
0
5
1
0
0
5
1
0
0
9
-1
-1
0
9
1
0
0
8
2
0
0
5
1
0
0
9
-1
-1
0
9
1
0...

result:

wrong answer 4th lines differ - expected: '3', found: '2'