「CQOI2015」任务查询系统
传送门
好像也是板子题???
区间修改,单点查询,考虑差分。
然后每次查询时就直接在对应的主席树上二分即可。
参考代码:
#include <cstdio>
#include <vector>
#define rg register
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while ('0' > c || c > '9') f |= c == '-', c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
}
typedef long long LL;
const int _ = 100010;
vector < int > vec1[_], vec2[_];
struct node { int lc, rc, cnt; LL sum; } t[_ << 6];
int n, m, tot, len, rt[_];
inline void update(int& p, int x, int k, int l = 1, int r = len) {
t[++tot] = t[p], t[tot].sum = t[p].sum + 1ll * x * k, t[tot].cnt = t[p].cnt + k, p = tot;
if (l == r) return ;
int mid = (l + r) >> 1;
if (x <= mid) update(t[p].lc, x, k, l, mid);
else update(t[p].rc, x, k, mid + 1, r);
}
inline LL query(int p, int k, int l = 1, int r = len) {
if (l == r) return min(t[p].sum, 1ll * k * l);
int mid = (l + r) >> 1, num = t[t[p].lc].cnt;
if (num >= k) return query(t[p].lc, k, l, mid);
else return query(t[p].rc, k - num, mid + 1, r) + t[t[p].lc].sum;
}
int main() {
#ifndef ONLINE_JUDGE
file("cpp");
#endif
read(m), read(n);
for (rg int s, e, p; m--; )
read(s), read(e), read(p), len = max(len, p), vec1[s].push_back(p), vec2[e + 1].push_back(p);
for (rg int i = 1; i <= n; ++i) {
rt[i] = rt[i - 1];
for (rg int j = 0; j < vec1[i].size(); ++j) update(rt[i], vec1[i][j], 1);
for (rg int j = 0; j < vec2[i].size(); ++j) update(rt[i], vec2[i][j], -1);
}
LL ans = 1;
for (rg int x, a, b, c, k, i = 1; i <= n; ++i) {
read(x), read(a), read(b), read(c);
k = (1ll * a * ans + b) % c + 1;
printf("%lld
", ans = query(rt[x], k));
}
return 0;
}