Advertisement
Josif_tepe

Untitled

Feb 25th, 2025
2,902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <fstream>
  5. #include <map>
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.    
  12.     int n, m;
  13.     cin >> n >> m;
  14.    
  15.     vector<int> v(m);
  16.     for(int i = 0; i < m; i++) {
  17.         cin >> v[i];
  18.     }
  19.    
  20.     unordered_map<int, int> T;
  21.     long long res = 0;
  22.     for(int i = 1; i <= m; i++) {
  23.         int e = v[i - 1];
  24.         res += n - 1;
  25.         res -= i - T[e] - 1;
  26.         T[e] = i;
  27.         cout << res << "\n";
  28.     }
  29.      
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement