QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212673#5459. Goose, goose, DUCK?zzzyzzz#WA 3ms32784kbC++172.2kb2023-10-13 19:21:282023-10-13 19:21:28

Judging History

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

  • [2023-10-13 19:21:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:32784kb
  • [2023-10-13 19:21:28]
  • 提交

answer

#include<bits/stdc++.h>
#include<sstream>
#include<cassert>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
const double eps=1e-7;
const int N=1e6+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}

int T,hackT;
int n,m,k;
int w[N];
int leap[N];
vector<int> vis[N];
int f[N][21];

void init() {
	for(int j=0;j<21;j++) {
		for(int i=1;i+(1<<j)-1<=n;i++) {
			if(!j) f[i][j]=leap[i];
			else f[i][j]=min(f[i][j-1],f[i+(1<<j-1)][j-1]);
		}
	}
}

int query(int l,int r) {
	if(l>r) swap(l,r);
	int len=r-l+1;
	int k=log(len)/log(2);
	return min(f[l][k],f[r-(1<<k)+1][k]);
}

void solve() {
	n=read(),k=read();
	
	for(int i=1;i<=n;i++) w[i]=read();
	
	if(k==1) {
		printf("0\n");
		return ;
	}
	
	for(int i=n;i>=1;i--) {
		vis[w[i]].push_back(i);
		if(vis[w[i]].size()>=k) leap[i]=vis[w[i]][vis[w[i]].size()-k];
		else leap[i]=n+1;
	}
	
	init();
	
	// printf("cc\n");
	// for(int i=1;i<=n;i++) printf("%d ",leap[i]);
	// printf("\n");
// 	
	// printf("%d\n",query(3,3));
	
	ll res=0;
	int l=1,r=1;
	while(l<=n) {
		while(r<=n&&query(l,r)>r+1) r++;
		// printf("l = %d,r = %d\n",l,r);
		res+=r-l+1;
		if(l==r) l++,r++;
		else l++;
	}
	
	printf("%lld\n",res);
}   

int main() {
    // init();
    // stin();
	// ios::sync_with_stdio(false); 

    // scanf("%d",&T);
    T=1; 
    while(T--) hackT++,solve();
    
    return 0;       
}          

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 3ms
memory: 32324kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 30696kb

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:

1943

result:

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