BZOJ2408 混乱的置换
这道题即THUSC 2015 t3...只不过数据范围$n, m ≤ 10^5$
可以上网查这个鬼畜的东西"Burrows-Wheeler Transform"
这道题要用到解压缩也就是IBWT算法,复杂度$O(n + m)$
/**************************************************************
Problem: 2408
User: rausen
Language: C++
Result: Accepted
Time:24 ms
Memory:884 kb
****************************************************************/ #include <cstdio> using namespace std;
const int N = 1e4 + ; int getint(); int n, m, st;
int a[N], next[N], cnt[]; int main() {
int i, j;
n = getint(), m = getint();
for (i = ; i <= n; ++i) ++cnt[(a[i] = getint()) + ];
for (i = ; i <= m; ++i) cnt[i] += cnt[i - ];
for (i = ; i <= n; ++i) next[++cnt[a[i]]] = i;
for (i = st = ; i <= n; ++i) if (a[i] < a[st]) st = i;
for (i = , j = st; i <= n; ++i) printf("%d%c", a[j], i == n ? '\n' : ' '), j = next[j];
return ;
} const int BUF_SIZE = ;
char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + ;
#define isdigit(x) ('0' <= x && x <= '9')
#define PTR_NEXT() { \
if (++buf_s == buf_t) \
buf_s = buf, buf_t = buf + fread(buf, , BUF_SIZE, stdin); \
} inline int getint() {
register int x = ;
while (!isdigit(*buf_s)) PTR_NEXT();
while (isdigit(*buf_s)) {
x = x * + *buf_s - '';
PTR_NEXT();
}
return x;
}
(p.s. 窝考试的时候sb。。。只想出来了$O(mn)$的算法QAQAQQQ)
BZOJ2408 混乱的置换的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【做题】agc016d - XOR Replace——序列置换&环
原文链接 https://www.cnblogs.com/cly-none/p/9813163.html 题意:给出初始序列\(a\)和目标序列\(b\),都有\(n\)个元素.每次操作可以把\(a\ ...
- [LeetCode] LFU Cache 最近最不常用页面置换缓存器
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the f ...
- [LeetCode] Longest Repeating Character Replacement 最长重复字符置换
Given a string that consists of only uppercase English letters, you can replace any letter in the st ...
- 页置换算法FIFO、LRU、OPT
页置换算法FIFO.LRU.OPT 为什么需要页置换 在地址映射过程中,若在页面中发现所要访问的页面不再内存中,则产生缺页中断.当发生缺页中断时操作系统必须在内存选择一个页面将其移出内存,以便为即将调 ...
- 【bzoj1231】[Usaco2008 Nov]mixup2 混乱的奶牛
题目描述 混乱的奶牛[Don Piele, 2007]Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S_i <= ...
- NOIP提高模拟题 混乱的队伍
混乱的奶牛 Description 混乱的奶牛 [Don Piele, 2007] Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 & ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
随机推荐
- IIS出现Service Unavailable 错误
IIS访问操作出现以下问题时要如何解决:
- Nudnik Photographer -Ural1260动态规划
Time limit: 1.0 second Memory limit: 64 MB If two people were born one after another with one second ...
- HTML5 canvas处理图片的各种效果,包括放大缩小涂鸦等
http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201502151385.html jQuery 缩放 旋转 裁剪图片 Image Cropper ...
- [DataBase] MongoDB (7) MongoDB 索引
MongoDB 索引 1. 建立索引 唯一索引db.passport.ensureIndex( {"loginname": 1}, {"unique": tru ...
- Python3基础 列表之间+ 合并,不去除重复项
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- jQuery实践——选择器篇
一.基本 #id: html:<div id="demo1">demo1</div> jQuery:$("#demo1").css( ...
- RSA3:预提取数据
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 用SignalR实现的弹幕功能
弹幕功能通常用于实时显示当前视频或者文档的评论内容,在上快速飞过的方式呈现,看起来比较酷炫. 这种典型的多用户实时交互的功能,很适合使用SignalR实现,通过SignalR提供后台的服务推送功能,客 ...
- Android手机_软件01
1.微信 下载:http://weixin.qq.com/ 2.QQ 下载:http://im.qq.com/download/ 3.滴滴打车(乘客端):http://www.xiaojukeji.c ...
- centos7 安装redis 开机启动
redis 下载 https://redis.io/download wget http://download.redis.io/releases/redis-3.2.6.tar.gz 解压缩 .ta ...