QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724517#9584. 顾影自怜wsxcbWA 389ms77416kbC++17998b2024-11-08 13:30:462024-11-08 13:30:47

Judging History

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

  • [2024-11-08 13:30:47]
  • 评测
  • 测评结果:WA
  • 用时:389ms
  • 内存:77416kb
  • [2024-11-08 13:30:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
typedef vector<vector<ll>> Mat;
//#define int long long
const int N=1e6+10,mod=1e9+7,inf=1e9+1,P=998244353;
const double pi=acos(-1.0),esp=1e-9;
const ll INF=1e18;
void solve()
{
	int n,k;
	cin>>n>>k;
	set<int>s;
	s.insert(0);
	s.insert(n+1);
	vector< vector<int> >pos(n+1);
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		pos[x].pb(i);
	}
	ll ans=0;
	for(int i=n;i;i--){
		if(!pos[i].size())continue;
		int last=*prev(s.lower_bound(pos[i][0]));
		int t=0,m=pos[i].size();
		while(t<m){
			int r=*s.upper_bound(pos[i][t]);
			if(t+k-1<m&&pos[i][t+k-1]<r)
			ans+=1ll*(pos[i][t]-last)*(r-pos[i][t+k-1]);
			last=pos[i][t];
			s.insert(pos[i][t]);
			t++;
		}
	}
	cout<<ans<<'\n';
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 389ms
memory: 77416kb

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: 122ms
memory: 3780kb

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

result:

wrong answer 19th lines differ - expected: '6', found: '7'