-
Notifications
You must be signed in to change notification settings - Fork 0
/
Breezy Mode Problem
55 lines (40 loc) Β· 939 Bytes
/
Breezy Mode Problem
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
#include <bits/stdc++.h>
using namespace std;
#define el endl
#define lo cout
// tous les crΓ©dits reviennent Γ Momo
#define do cin
#define loop(n) for(int i=0;i<n;i++)
#define test int t;cin>>t;while(t--)
int main()
{
cin.tie(0)->sync_with_stdio(0);
unordered_map<long long,long long> m;
long long n,q;
cin>>n>>q;
long long a[n];
loop(n)
{
cin>>a[i];
m[a[i]]++;
}
long long c=0;
for( auto it=m.begin();it!=m.end();it++)
{
long long momo= it->second;
c+=(momo*(momo+1))/2;
}
loop(q)
{
long long p,x;
cin>>p>>x;
c-=(m[a[p-1]]*(m[a[p-1]]+1))/2;
c-=(m[x]*(m[x]+1))/2;
m[a[p-1]]--;
m[x]++;
c+=(m[a[p-1]]*(m[a[p-1]]+1))/2;
c+=((m[x])*(m[x]+1))/2;
a[p-1]=x;
cout<<c<<el;
}
}