-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path352B.cpp
60 lines (56 loc) · 1.33 KB
/
352B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> sequence(n);
map<int,pair<int,int>> get_element;
vector<int> answer;
map<int,bool> isAP;
for(int i=0;i<n;i++)
{
cin>>sequence[i];
int x=sequence[i];
if(get_element.find(x)==get_element.end()) //first occurance
{
get_element[x]={i,-1};
isAP[x]=true;
}
else
{
int diff=i-get_element[x].first;
if(get_element[x].second==-1)
{
get_element[x].second=diff;
}
else if(diff!=get_element[x].second)
{
isAP[x]=false;
}
get_element[x].first=i;
}
}
int count=0;
for(auto &x:get_element)
{
if(isAP[x.first])
{
count++;
answer.push_back(x.first);
if(x.second.second==-1)
{
answer.push_back(0);
}
else
answer.push_back(x.second.second);
}
}
cout<<count<<endl;
for(int i=0;i<answer.size();i+=2)
{
cout<<answer[i]<<" "<<answer[i+1]<<endl;
}
}