当前位置: 代码迷 >> 综合 >> NOIP2017 D2T3 列队
  详细解决方案

NOIP2017 D2T3 列队

热度:4   发布时间:2024-01-09 11:36:47.0

列队

题目背景:

NOIP2017 D2T3

分析:平衡树 or 线段树 or 树状数组

 

考场上因为自己不会实现,所以没有过掉这道题,拿了80的暴力,50分的暴力,和30分的平衡树,50分因为询问次数较少,可以直接提取出对应影响到的行,和最后一列,然后直接暴力维护即可,然后对于30分的只询问第一行,相当于,只会影响到第一行和最后一列,直接将两者接到一起,用平衡树暴力维护删除中间一个数,放到最后就可以了。

 

Source

/*created by scarlyw
*/
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <vector>inline char read() {static const int IN_LEN = 1024 * 1024;static char buf[IN_LEN], *s, *t;if (s == t) {t = (s = buf) + fread(buf, 1, IN_LEN, stdin);if (s == t) return -1;}return *s++;
}template<class T>
inline void R(T &x) {static char c;static bool iosig;for (c = read(), iosig = false; !isdigit(c); c = read()) {if (c == -1) return ;if (c == '-') iosig = true;}for (x = 0; isdigit(c); c = read())x = ((x << 2) + x << 1) + (c ^ '0');if (iosig) x = -x;
}const int OUT_LEN = 1024 * 1024;
char obuf[OUT_LEN], *oh = obuf;
inline void write_char(char c) {if (oh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf;*oh++ = c;
}template<class T>
inline void W(T x) {static int buf[30], cnt;if (x == 0) write_char('0');else {if (x < 0) write_char('-'), x = -x;for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;while (cnt) write_char(buf[cnt--]);}
}inline void flush() {fwrite(obuf, 1, oh - obuf, stdout);
}const int MAXQ = 300000 + 10;int n, m, q, x, y;
struct data {int x, y;
} query[MAXQ];inline void solve_small() {static const int MAXQ = 500 + 10;static const int MAXN = 50000 + 10;static long long pos[MAXQ][MAXN], last[MAXN];static int xx[MAXQ], h[MAXN];for (int i = 1; i <= q; ++i) R(query[i].x), R(query[i].y), xx[i] = query[i].x;std::sort(xx + 1, xx + q + 1);int cnt = 1;for (int i = 2; i <= q; ++i) if (xx[i] != xx[i - 1]) xx[++cnt] = xx[i];for (int i = 1; i <= cnt; ++i) h[xx[i]] = i;for (int i = 1; i <= cnt; ++i)for (int j = 1; j < m; ++j)pos[i][j] = (long long)(xx[i] - 1) * m + j;for (int i = 1; i <= n; ++i) last[i] = (long long)i * m;for (int i = 1; i <= q; ++i) {int x = query[i].x, y = query[i].y, hh = h[x];long long zz;if (y != m) zz = pos[hh][y];else zz = last[x];W(zz), write_char(