1 条题解
-
0

一开始还以为模板出问题了,使用C语言+快读竟然比C++普通解绑+string还要慢???
ok是我自己唐了,初始化已读入自写缓冲区所有数据,定义一个大数组是一种重复浪费资源的行为时刻,你需要驾驭你的模板
分析
如果走错了,那么将错误的位置与正确位置调换,发现不改变寻址的过程,于是模拟一次即可
AC代码
#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> #define N1 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 #define N2 N1, N1, N1, N1, N1, N1, N1, N1, N1, N1 #define N3 N2, N2, N2, N2, N2, N2, N2, N2, N2, N2 #define N4 N3, N3, N3, N3, N3, N3, N3, N3, N3, N3 #define D(a) a, 1##a, 2##a, 3##a, 4##a, 5##a, 6##a, 7##a, 8##a, 9##a #define S246 N2, N2, N1, N1, N1, N1, -1, -1, -1, -1, -1, -1 const int _mp[0x10000] = {N4, N3, N3, N2, N2, N2, N1, N1, N1, -1, -1, -1, -1, -1, -1, D(0), S246, D(1), S246, D(2), S246, D(3), S246, D(4), S246, D(5), S246, D(6), S246, D(7), S246, D(8), S246, D(9), N4, N4, N4, N4, N4, N2, N2, N2, N2, N2, N2, N2, N2, N1, N1, N1, N1, N1, N1, N1, N1, -1, -1, -1, -1, -1, -1}; #undef N1 #undef N2 #undef N3 #undef N4 #undef D #undef S246 char *buf_ptr; char *buf_end; char out_buf[1 << 20]; char *pp = out_buf; void io_init() { struct stat sb; fstat(0, &sb); buf_ptr = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, 0, 0); buf_end = buf_ptr + sb.st_size; } int read_() { int x = 0, f = 0; while (buf_ptr < buf_end && *buf_ptr <= ' ') buf_ptr++; if (buf_ptr >= buf_end) return 0; if (*buf_ptr == '-') { f = 1; buf_ptr++; } while (buf_ptr + 1 < buf_end) { int v = _mp[*(uint16_t *)buf_ptr]; if (v == -1) break; x = x * 100 + v; buf_ptr += 2; } if (buf_ptr < buf_end && *buf_ptr >= '0' && *buf_ptr <= '9') { x = x * 10 + (*buf_ptr - '0'); buf_ptr++; } return f ? -x : x; } void push(char c) { if (pp - out_buf == (1 << 20)) { fwrite(out_buf, 1, 1 << 20, stdout); pp = out_buf; } *pp++ = c; } void write_(int x) { if (x < 0) { push('-'); x = -x; } static int sta[40]; int top = 0; do { sta[top++] = x % 10; x /= 10; } while (x); while (top) push(sta[--top] + '0'); } void write_str(const char *s) { while (*s) push(*s++); } void io_flush() { fwrite(out_buf, 1, pp - out_buf, stdout); } int gc() { return (unsigned char)*buf_ptr++; } static inline void mvp(int n) { buf_ptr += n; } int n, m, r, l, steve; int main() { io_init(); int t = read_(); while (t--) { n = read_(); m = read_(); char *s = buf_ptr; buf_ptr += n + 1; l = 0; r = n + 1; while (l + 1 != r) { steve = (r + l) >> 1; if (s[steve] == 'R') l = steve;else r = steve; }if (r == m)write_(0); else if (r > m) {write_(m);push(' ');write_(r); }else {write_(r);push(' ');write_(m); }push('\n'); } io_flush(); return 0; }
信息
- ID
- 150
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 53
- 已通过
- 6
- 上传者