题解 | #小红的区间查询#

小红的区间查询

https://www.nowcoder.com/practice/cbaecf16197a4136b8a593a7a270f4ab

老朋友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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-20 14:01
点赞 评论 收藏
分享
今天 15:48
上海交通大学 C++
今天投了小鹏,收到了AI面,大概会问哪些啊?
期末一定及格:总共4个部分,心理测评、行测、然后就是问岗位、对岗位的理解、过往遇到了哪些难点怎么解决,很简单,没有什么特别专业的问题,都是一些综合素质相关的
点赞 评论 收藏
分享
程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
06-23 18:25
沈阳大学 Java
HR已读不回,是我说话方式不对吗?
大白之主:你是串子吗? hr: 我们不招人了,把岗位挂着boss只是因为我闲得慌
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务