首页 > 代码库 > [原创题] count 分段Hash
[原创题] count 分段Hash
题意
实现
#include <cstdio> #include <cstring> #include <cstdlib> #include <cctype> #include <map> using namespace std; #define F(i, a, b) for (register int i = (a); i <= (b); i++) const int N = 300000; int n, m, a[N]; int M; map<int, int> h; inline int rd(void) { int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ‘-‘) f = -1; int x = 0; for (; isdigit(c); c = getchar()) x = x*10+c-‘0‘; return x*f; } inline void Modify(int x, int w, int d) { for (x += M; x > 0; x >>= 1) h[x][w] += d; } inline void Query(int L, int R, int w) { int sum = 0; for (L = L-1+M, R = R+1+M; L^R^1; L >>= 1, R >>= 1) { if (!(L&1)) sum += h[L^1].count(w) ? h[L^1][w] : 0; if (R&1) sum += h[R^1].count(w) ? h[R^1][w] : 0; } return sum; } int main(void) { #ifndef ONLINE_JUDGE freopen("count.in", "r", stdin); freopen("count.out", "w", stdout); #endif n = rd(), m = rd(); for (M = 1; M < n+2; M <<= 1); F(i, 1, n) Modify(i, a[i] = rd(), 1); F(i, 1, m) { int k = rd(); if (k == 1) { int x = rd(), w = rd(); Modify(x, a[x], -1); Modify(x, a[x] = w, 1); } else { int l = rd(), r = rd(), w = rd(); printf("%d\n", Query(l, r, w)); } } return 0; }
[原创题] count 分段Hash
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。