题解 | #彩虹涂鸦#

彩虹涂鸦

https://www.nowcoder.com/practice/507cf29e541545c18968fd0436ad8b23

直接模拟即可

#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> color(n, 0);
    vector<int> time(n, 0);
    while (q!=0) {
        q--;
        int opt;
        cin >> opt;
        if(opt==1){
            int l, r, k;
            cin >> l >> r >>k;
            vector<int> a(k);
            for(int i=0;i<k;i++) cin >> a[i];
            int counter = 0;
            for(int i=l-1;i<=r-1;i++){
                if(color[i]!=a[counter%k]){
                    time[i]++;
                    color[i] = a[counter%k];
                }
                counter++;
            }
        }
        else if(opt==2){
            int pos;
            cin >> pos;
            cout << time[pos-1] << " " << color[pos-1] << endl;
        } 
        else if(opt==3){
            int l,r;
            cin >> l >> r;
            unordered_map<int, int> counter;
            for(int i=l-1;i<=r-1;i++) counter[color[i]]++;
            int tmp = 0;
            for(auto x: counter) tmp = max(x.second, tmp);
            cout << tmp << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
无实习如何秋招上岸
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-27 20:15
还能挽救吗?找同学帮忙看了一下&nbsp;字节怎么能如此对我
牛客26396789...:你这是严重红线,被发现你自己永远进不去,你那个同学直接走人,你还敢宣扬
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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