dificilcoder's blog

By dificilcoder, history, 3 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 2   Vote: I like it +19 Vote: I do not like it

CEO, entrepreneur

Born in 1964

Jeffrey, Jeffrey Periods

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Check This. 126191039