题意
Sol
ODT板子题。就是用set维护连续段的大暴力。。
然鹅我抄的板子本题RE提交AC??。。
具体来说,用50 50 658073485 946088556
这个数据测试下面的代码,然后在79行停住,看一下bg和i的值会发生神奇的事情。。
问题已解决,确实是那位博主写错了, 只要把split(l)和split(r + 1)反过来就行了
#include<bits/stdc++.h>
#define LL long long
#define int long long
#define sit set<Node>::iterator
#define fi first
#define se second
using namespace std;
const int MOD = 1e9 + 7, MAXN = 1e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, mod;
template<typename A, typename B> inline int mul(A x, B y) {
return 1ll * x * y % mod;
}
template<typename A, typename B> inline void add2(A &x, B y) {
x = (x + y % mod);
}
LL seed, vmax;
int a[MAXN];
int rnd() {
int ret = seed;
seed = (seed * 7 + 13) % MOD;
return ret;
}
struct Node {
int l, r;
mutable LL v;
bool operator < (const Node &rhs) const {
return l < rhs.l;
}
};
set<Node> s;
sit split(int p) {
auto pos = s.lower_bound({p});
if(pos != s.end() && pos->l == p) return pos;
pos--;
int L = pos->l, R = pos->r, V = pos->v;
s.erase(pos);
s.insert({L, p - 1, V});
return s.insert({p, R, V}).fi;
}
void Add(int l, int r, int val) {
auto bg = split(l), ed = split(r + 1);
for(auto i = bg; i != ed; i++) i->v += val;
}
void Mem(int l, int r, int val) {
for(int i = l; i <= r; i++) a[i] = val;
auto bg = split(l), ed = split(r + 1);
s.erase(bg, ed);
s.insert({l, r, val});
}
int rak(int l, int r, int x) {
vector<pair<LL, int>> v;
auto bg = split(l), ed = split(r + 1);
for(auto i = bg; i != ed; i++)
v.push_back({i->v, i->r - i->l + 1});
sort(v.begin(), v.end());
for(auto it = v.begin(); it != v.end(); it++) {
x -= it -> se;
if(x <= 0) return it -> fi;
}
assert(0);
}
int fp(int a, int p) {
int base = 1; a %= mod;
while(p) {
if(p & 1) base = 1ll * base * a % mod;
a = 1ll * a * a % mod; p >>= 1;
}
return base;
}
int po(int l, int r, int x) {
if(l == 6 && r == 7) {
puts("G");
}
auto bg = split(l);
printf("%d %d %d %d\n", bg->l, bg->r, bg->v);
auto ed = split(r + 1);
int ans = 0;
for(sit i = bg; i != ed; i++) {
printf("%d %d %d %d\n", i->l, i->r, i->v);
ans = (ans + (i->r - i->l + 1) * fp(i->v, x) % mod) % mod;
}
return ans;
}
signed main() {
N = read(); M = read(); seed = read(); vmax = read();
for(int i = 1; i <= N; i++) a[i] = (rnd() % vmax) + 1, s.insert({i, i, a[i]});
s.insert({N + 1, N + 1, 0});
for(int i = 1; i <= M; i++) {
int op = (rnd() % 4) + 1; int l = (rnd() % N) + 1; int r = (rnd() % N) + 1, x = -1;
if(l > r) swap(l, r);
if(op == 3) x = (rnd() % (r - l + 1)) + 1;
else x = (rnd() % vmax) + 1;
if(op == 4) mod = (rnd() % vmax) + 1;
if(op == 1) Add(l, r, x);
else if(op == 2) Mem(l, r, x);
else if(op == 3) cout << rak(l, r, x) << '\n';
else cout << po(l, r, x) << '\n';
}
return 0;
}
/*
50 50 658073485 946088556
*/
原文地址:https://www.cnblogs.com/zwfymqz/p/10357168.html
时间: 2024-10-31 23:22:40