[Noi2014]随机数生成器

题面

传送门

Sol

这道题卡空间。。。
先模拟出T,大力贪心,每次选最小的走显然最优
那么选了 (i,j) 它上面都只能选第 j 列以前的,它下面都只能选第j列以后的
每次选最小,更新每行能选的区间,判断即可

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(25000005);

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int n, m, q, X[_], T[_], len, l[5010], r[5010];

int main(RG int argc, RG char* argv[]){
    X[0] = Read(); RG int A = Read(), B = Read(), C = Read(), D = Read(); n = Read(); m = Read(); q = Read(); len = n * m;
    for(RG int i = 1; i <= len; ++i) X[i] = (1LL * A * X[i - 1] % D * X[i - 1] % D + 1LL * B * X[i - 1] % D + C) % D;
    for(RG int i = 1; i <= len; ++i) T[i] = i;
    for(RG int i = 1; i <= len; ++i) swap(T[i], T[X[i] % i + 1]);
    for(RG int i = 1, x, y; i <= q; ++i) x = Read(), y = Read(), swap(T[x], T[y]);
    for(RG int i = 1; i <= len; ++i) X[T[i]] = i;
    for(RG int i = 1; i <= n; ++i) l[i] = 1, r[i] = m;
    for(RG int i = 1, tot = 0; i <= len && tot < n + m; ++i){
        RG int x = (X[i] + m - 1) / m, y = X[i] % m; if(!y) y += m;
        if(l[x] <= y && r[x] >= y){
            ++tot; printf("%d", i); if(tot != n + m - 1) printf(" ");
            for(RG int j = x + 1; j <= n; ++j) l[j] = max(l[j], y);
            for(RG int j = 1; j < x; ++j) r[j] = min(r[j], y);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值