跳到正文

个人记录

暂存

AaronLiu0402约 2 分钟
原文

这是 2026年9月20日 存档的第 5 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年9月11日
收录
2026年9月11日
更新
2026年11月10日
篇幅
约 2 分钟
获赞
1

版本

  1. v6当前
  2. v5
  3. v4
  4. v3
更早的 2 个版本
  1. v2
  2. v1

我是标题

C++
#include<bits/stdc++.h>
using namespace std;
int n,q;
int a[8005];
map<int,int>mp;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    while(q--){
        int idx; 
        cin>>idx;
        if(idx==1){
            int x,v;
            cin>>x>>v;
            mp[a[x]]--;
            mp[v]++;
            a[x]=v;
        }
		else{
            int x;
            cin>>x;
            int cnt=1;
            for(int i=1;i<x;i++){
                if(a[i]==a[x]){
                    cnt++;
                }
            }
            int ans=0;
            for(auto it:mp){
                if(it.first==a[x]){
                    ans+=cnt;
                    break;
                }
				else{
                    ans+=it.second;
                }
            }
            cout<<ans<<'\n';
        }
    }
    return 0;
}