Just see code enclosed between '' in comment. It outputs all '0s' and nothing else. Why is it producing only 0s and not the elements i just inserted into stl Map ?
For example if my input is '3,45,6,3,1' then output should be '1,2,3,1,5' ,shouldn't it be?
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
lli k,o[1000010];
int n,tmp=0,i,uq=0,what,ans=1;
map<lli,int> tp;
int main() {
cin>>n>>k;
//<tagz
for (i=1;i<=n;i++) {
cin>>o[i];
if (tp[o[i]]==0) uq++;
tp.insert(make_pair(o[i],i));
cout<<tp[o[i]]<<",";
tmp=max(tmp,tp[o[i]]);
}
// /tagz>
//cout<<"ZZZ:tmp="<<tmp<<" ,uq="<<uq<<endl;
cout<<"ZZZ:"<<tp[2]<<endl;
if (uq<k) {
cout<<"0";
return 0;
}
i=tmp;int fck=0;
for (;i<n;i++) {
fck++;if (fck==200) break;
// cout<<"AT "<<i<<endl;
uq=1;tmp=0;
map<lli,int> yo;
for (int j=i+1;j<n;j++) {
if (o[j]!=o[i]) {
if (yo[o[j]]==0) uq++;
yo.insert(make_pair(o[j],j));
tmp=max(tmp,yo[o[j]]);
}
}
if (uq<k) {
cout<<ans;
return 0;
}
// cout<<" Uq="<<uq<<", tmp="<<tmp<<endl;
ans++;
i=tmp;
}
cout<<ans;
}