老朋友map又来了
#include <iostream> #include <queue> #include <map> #include <set> #include <cmath> #include <cstring> #include <algorithm> #include <iomanip> #include <stack> #include <numeric> #include <ctime> #include <string> #include <bitset> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; const ll N = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f; int n, q, a[205]; map<int, int>mp[205]; //前i个里面有多少个vlu void solve() { cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; for (int j = i; j <= n; j++)mp[j][a[i]]++; } while (q--) { int op, pos, x; cin >> op >> pos >> x; if (op == 1) { for (int i = pos; i <= n; i++) { mp[i][a[pos]]--; mp[i][x]++; } a[pos] = x; } else { cout << mp[pos][x] << '\n'; } } } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; //cin>>t; while (t--) { solve(); } return 0; }