### dificilcoder's blog

By dificilcoder, history, 17 months ago,

#### 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();
}
}



• 0

| Write comment?
 » 17 months ago, # | ← Rev. 2 →   +19 CEO, entrepreneurBorn in 1964Jeffrey, Jeffrey Periods
 » 17 months ago, # |   0 Check This. 126191039