QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712216#9584. 顾影自怜xydCatGirl#WA 111ms37180kbC++201.9kb2024-11-05 14:56:462024-11-05 14:56:47

Judging History

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

  • [2024-11-05 14:56:47]
  • 评测
  • 测评结果:WA
  • 用时:111ms
  • 内存:37180kb
  • [2024-11-05 14:56:46]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int n;
bool book[N];
struct dsu{
    int f[N];
    int sz[N];
    void init(){
        for(int i=1;i<=n;++i){
            f[i]=i;
            sz[i]=1;
        }
    } 
    int get_f(int t){
        if(f[t]==t)return t;
        return f[t]=get_f(f[t]);
    }
    int siz(int t){
        if(!book[t])return 0;
        return sz[get_f(t)];
    }
    void merge(int x,int y){
        x=get_f(x);y=get_f(y);
        if(x==y)return;
        sz[y]+=sz[x];
        f[x]=y;
    }
} d;
int genshin;
int k;
int v=0;
vector<int>vec[N];
void change(int x){
    book[x]=1;
    if(book[x+1])d.merge(x,x+1);
    if(book[x-1])d.merge(x,x-1);
}
int pre[N];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>genshin;
    while(genshin--){
        cin>>n>>k;
        v=0;
        for(int i=1;i<=n;++i){
            int x;
            cin>>x;
            v=max(v,x);
            vec[x].push_back(i);
        }
        d.init();
        int ans=0;
        for(int i=1;i<=v;++i){
            int lst=0,c0=0;
            for(int j=0;j<vec[i].size();++j){
                int x=vec[i][j];
                pre[x]=d.siz(x-1);
                while(j-lst>=k){
                    change(lst);
                    ++lst;
                }
                int y=vec[i][lst];
                if(j-lst==k-1){
                    // cout<<j<<" "<<lst<<endl;
                    if(pre[x]-pre[y]==x-y){
                        // cout<<x<<" "<<d.siz(x+1)<<endl;
                        ans+=(d.siz(x+1)+1)*(pre[y]+1);
                    }
                }
                change(x);
            }
            vec[i].clear();
        }
        for(int i=0;i<=n+1;++i)book[i]=0;
        // for(int i=1;i<=n;++i)cout<<pre[i]<<" ";
        // cout<<endl;
        cout<<ans<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7688kb

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: 48ms
memory: 37180kb

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: 111ms
memory: 7724kb

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
3
0
3
0
3
1
6
3
1
6
1
0
6
1
0
6
0
0
6
2
0
6
0
0
6
0
0
6
0
0
6
2
0
9
1
0
6
1
0
6
0
0
6
2
0
6
3
1
6
1
0
6
0
0
6
0
0
6
2
0
9
1
0
6
0
0
6
1
0
6
0
0
12
1
0
6
1
0
6
2
0
6
2
0
6
3
1
10
6
3
1
10
3
1
0
10
3
1
0
10
3
1
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10...

result:

wrong answer 37th lines differ - expected: '6', found: '9'