BZOJ3671 [Noi2014]随机数生成器
来源:互联网 发布:mac怎么循环播放视频 编辑:程序博客网 时间:2024/05/18 03:04
[Solution]
I thought of size-balanced tree at first, the got only 60 at the exams. In fact, we can just modify two arrays ml[i] and mr[i] meaning the left and the right pos that the number can be that row. Because there are many queries but few changes, it can get AC. What a pity that I didn't come up with that while examing.
[Code]
#define PROC "random"#include <cstdio>#include <cctype>#include <memory.h>#include <algorithm> using namespace std; int nextInt() { int d, s = 0; do d = getchar(); while (!isdigit(d)); do s = s * 10 + d - 48, d = getchar(); while (isdigit(d)); return s;} #define _l (long long int)#define mkword(a,b) (((a)<<16)|(b))#define hiword(a) ((a)>>16)#define loword(a) ((a)&65535) const int maxn = 5009;const int inf = 0x3f3f3f3f; int n, m, t, a[maxn][maxn], r[maxn * maxn], ans[maxn * 2], ml[maxn], mr[maxn]; void init() { int x, a, b, c, d, q; x = nextInt(); a = nextInt(); b = nextInt(); c = nextInt(); d = nextInt(); n = nextInt(); m = nextInt(); q = nextInt(); t = n * m; for (int i = 1; i <= t; i ++) r[i] = i; for (int i = 1; i <= t; i ++) { x = (_l a * (_l x * x % d) % d + _l b * x % d + c) % d; swap(r[i], r[x % i + 1]); } for (int i = 0; i < q; i ++) { int u = nextInt(); int v = nextInt(); swap(r[u], r[v]); } for (int i = 0; i < n; i ++) for (int j = 0; j < m; j ++) ::a[i][j] = r[i * m + j + 1]; for (int i = 0; i < n; i ++) for (int j = 0; j < m; j ++) r[::a[i][j]] = mkword(i + 1, j + 1);} void solve() { for (int i = 1; i <= n; i ++) ml[i] = 1, mr[i] = m; for (int i = 0, p = 1; i < m + n - 1; i ++) { while (ml[hiword(r[p])] > loword(r[p]) || mr[hiword(r[p])] < loword(r[p])) p ++; for (int j = 1; j < hiword(r[p]); j ++) mr[j] = min(mr[j], loword(r[p])); for (int j = hiword(r[p]) + 1; j <= n; j ++) ml[j] = max(ml[j], loword(r[p])); ans[i] = p ++; }} int main() {#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif init();// debugPrint(); solve(); for (int i = 0; i < (m + n - 1); i ++) printf("%d%c", ans[i], ((i < (n + m - 2)) ? 32 : 10));// putchar(10); return 0;}
0 0
- BZOJ3671 [Noi2014]随机数生成器
- 【BZOJ3671】【NOI2014】随机数生成器
- [BZOJ3671][Noi2014]随机数生成器
- bzoj3671: [Noi2014]随机数生成器
- [BZOJ3671][Noi2014]随机数生成器 && 贪心
- bzoj3671[Noi2014]随机数生成器(贪心)
- 【BZOJ3671】[Noi2014]随机数生成器【模拟】【贪心】【卡空间】
- 【NOI2014】随机数生成器
- NOI2014 随机数生成器
- [COGS1767] [NOI2014]随机数生成器
- 3671: [Noi2014]随机数生成器
- 【NOI2014】随机数生成器
- #6. 【NOI2014】随机数生成器
- 3671: [Noi2014]随机数生成器
- [jzoj3757]【NOI2014】随机数生成器
- [NOI2014]随机数生成器
- bzoj 3671: [Noi2014]随机数生成器
- BZOJ-3671 [Noi2014]随机数生成器
- SDUTOJ【2780】 pots---bfs
- spring技术内幕17-Spring HTTP调用器实现远程调用
- FFmpeg转码指令(测试通过)
- HDU 4891 The Great Pan(模拟)
- HDU[1253]--bfs
- BZOJ3671 [Noi2014]随机数生成器
- hdu1010 dfs
- CF 17B Hierarchy
- c++驱动编译出错解决方法
- 双目测量心得
- HDU 4893 Wow! Such Sequence!(线段树)
- shell的条件与控制
- 性能调优攻略
- 编程范式思考问题