标签:clu 而且 etc lap 数据 long def lse highlight
学数据结构学傻了系列
间的询问较少,所以中间的询问的复杂度可以高一些
考虑怎么做这个东西
发现是最后统一询问,而且询问的东西比较怪,每个位置是个定值
可以前缀和搞
考虑差分,中间的区间加操作也是可以差分的
因为中间的询问很少所以其实在线暴力计算就好了
代码:
#include <algorithm> #include <iostream> #include <cstdlib> #include <cctype> #include <cstdio> using namespace std; typedef long long ll; const int MAX_N = 80005; int n, q, mod, max_val, min_val; ll dlt[MAX_N]; int pre_sum[MAX_N]; inline int rd() { register int x = 0, c = getchar(); register bool f = false; while (!isdigit(c)) { f = (c == ‘-‘); c = getchar(); } while (isdigit(c)) { x = x * 10 + (c ^ 48); c = getchar(); } return f ? -x : x; } inline int get_c() { register int c = getchar(); while (!isupper(c)) c = getchar(); return c; } inline void query(int l, int r) { ll sig = 0ll, tmp, res = 0ll; for (int i = 1; i < l; ++i) sig = sig + dlt[i]; for (int i = l; i <= r; ++i) { sig += dlt[i]; tmp = sig * i % mod; res += (min_val <= tmp && tmp <= max_val); } printf("%lld\n", res); } int main() { n = rd(); q = rd(); mod = rd(); min_val = rd(); max_val = rd(); register int opt, lef, rig, val; while (q--) { opt = get_c(); if (opt == ‘A‘) { lef = rd(); rig = rd(); val = rd(); dlt[lef] = dlt[lef] + val; dlt[rig + 1] = dlt[rig + 1] - val; } else { lef = rd(); rig = rd(); query(lef, rig); } } register ll sig = 0ll, tmp; for (int i = 1; i <= n; ++i) { sig = sig + dlt[i]; tmp = sig * i % mod; pre_sum[i] = pre_sum[i - 1] + (min_val <= tmp && tmp <= max_val); } q = rd(); while (q--) { lef = rd(); rig = rd(); printf("%d\n", pre_sum[rig] - pre_sum[lef - 1]); } return 0; }
标签:clu 而且 etc lap 数据 long def lse highlight
原文地址:https://www.cnblogs.com/xcysblog/p/9879936.html