Help to solve Jeff and Periods problem

Revision en1, by dificilcoder, 2021-08-17 17:48:36

#### Help! How to modify this code to solve Jeff and Periods problem

352B - Jeff and Periods

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl "\n"
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define fi first
#define se second

void solve() {
int n;
cin>>n;
int a;
map<int, pair<int, int>> res;

for(int i=1; i<=n; i++){
cin>>a;
if(res[a].first){
if(res[a].second ==0){
res[a].second = i;
}
}else{
res[a].first = i;
}
}
cout<<res.size()<<nl;
for(auto itr = res.begin(); itr!=res.end(); itr++) {
if(itr->second.second) {
cout<<itr->first<<" "<<itr->second.second - itr->second.first<<nl;
}else{
cout<<itr->first<<" "<<0<<nl;
}
}
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t=1;
// cin>>t;
while(t--) {
solve();
}
}



#### History

Revisions

Rev. Lang. By When Δ Comment
en1 dificilcoder 2021-08-17 17:48:36 1147 Initial revision (published)