题解 | #彩虹涂鸦#
彩虹涂鸦
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")