hihoCoder 1236 Scores 解题报告(bitset + 分段暴力)
来源:互联网 发布:js 字符串 match 编辑:程序博客网 时间:2024/05/17 03:32
#1236 : Scores
- 样例输入
22 31 1 1 1 12 2 2 2 2 21 1 1 1 13 3 3 3 33 51 1 1 1 11 1 1 1 11 2 3 4 521 1 1 1 11 1 1 1 1
- 样例输出
1222
- 解题报告: 求五维皆小于的数量。使用bitset记录当前某个维度,分数不大于给定查询的序号,最终对5个维度的bitset进行与操作。因为查询数量较多,故可以分段预处理。复杂度为O(n * sqrt(n) * M),M为bitset与操作的常数复杂度。样例很少,所以AC还是可以的。代码如下:
描述
Kyle is a student of Programming Monkey Elementary School. Just as others, he is deeply concerned with his grades.
Last month, the school held an examination including five subjects, without any doubt, Kyle got a perfect score in every single subject.
There are n students took part in this examination(not including Kyle), and everyone got an integer between 1 to m as the score of one subject.
Now, looking at the grade table of these n students, Kyle wants to know how many students still did no better than him even if his scores are something else – Here, “no better” means there is no subject in which the student got strictly greater score than Kyle.
输入
There are multiple test cases.
The first line of the input contains an integer T (T <= 3) which means the number of test cases.
The first line of each test case contains two integers, n, m(n, m≤ 50,000), which are the number of students and the perfect score of each subject.
In the next n lines, each line consists of five integers, indicating a student’s scores.
Then one line follows. This line contains an integer q(q≤ 50,000) indicating the number of queries.
In the next q lines, each line contains five integers as well, representing a query. Each query indicates a set of scores, and for each query, you should figure out that if Kyle's grade is this set of scores, how many students still did no better than him. But for the sake of security, only the first query is in its original form, and other queries are encrypted. To decrypt a query, you must let each integer in the query do xor operation with the answer of last query. It's guaranteed that all the decrypted queries contain integers between 1 and 50000.
输出
For each test case, you should output q lines as the answer for all queries.
提示
In case 1, there are two students with different scores and the scores of the first student (1, 1, 1, 1, 1) are not larger than the first query (1 1 1 1 1) in every subject, so the answer for this query is 1.
After having xor operation with the last answer 1, the second query (3,3,3,3,3) will be decrypted into (2, 2, 2, 2, 2). Because both students’ scores are no better than (2, 2, 2, 2, 2), so the answer for query 2 is 2.
#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>#include <set>#include <map>#include <queue>#include <vector>#include <functional>#include <cassert>#include <bitset>#include <list>using namespace std;typedef long long ll;typedef unsigned long long ull;#define ff(i, n) for(int i=0,END=(n);i<END;i++)#define fff(i, n, m) for(int i=(n),END=(m);i<=END;i++)#define dff(i, n, m) for(int i=(n),END=(m);i>=END;i--)#define travel(e, u) for(int e=first[u], v=vv[first[u]]; ~e; e=nxt[e])#define mid ((l+r)/2)#define bit(n) (1ll<<(n))#define clr(a, b) memset(a, b, sizeof(a))#define debug(x) cout << #x << " = " << x << endl;#define ls (rt << 1)#define rs (ls | 1)#define lson l, m, ls#define rson m + 1, r, rsvoid work();template<typename T>void read(T & x) { char ch = getchar(); while((ch < '0' || ch > '9') && ch != '-') ch = getchar(); bool flag = (ch == '-'); if (flag) ch = getchar(); x = 0; while(ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } if (flag) x = -x;}template<typename T>void print(T v) { if (v < 0) { putchar('-'); print(-v); } else { if (v < 10) { putchar('0' + v); } else { print(v / 10); putchar(v % 10 + '0'); } }}int main() { work(); return 0;}/**************************Beautiful GEGE**********************************/const int maxn = 50005;pair<int, int> node[5][maxn];bitset<maxn> stu[5][250];void work() { int T; scanf("%d", &T); fff(cas, 1, T) { int n, m; read(n), read(m); ff(j, n) { ff(i, 5) { int s; read(s); node[i][j] = make_pair(s, j); } } ff(i, 5) { sort(node[i], node[i] + n); int top = 0; ff(j, n) { if ((j & 255) == 0) stu[i][top + 1] = stu[i][top], top ++; stu[i][top].set(node[i][j].second); } } int q; read(q); int ans = 0; while(q --) { bitset<maxn> u; u.flip(); ff(i, 5) { int v; scanf("%d", &v); v ^= ans; int pos = upper_bound(node[i], node[i] + n, make_pair(v, maxn)) - node[i] - 1; if (pos == -1) { u.reset(); continue; } bitset<maxn> now = stu[i][pos >> 8]; fff(j, pos & ~255, pos) { now.set(node[i][j].second); } u = u & now; } ans = u.count(); print(ans); puts(""); } }}
- hihoCoder 1236 Scores 解题报告(bitset + 分段暴力)
- 解题报告:hihoCoder_1236 Scores 分块bitset暴力
- HihoCoder 1236 Scores (五维偏序bitset+分块)
- hihoCoder 1236:Scores(bitset+分块)
- Hihocoder 1236 Scores【分块+bitset】
- hihoCoder 1236 Scores(bitset+分块)
- HihoCoder-1236-Scores【bitset】【五维偏序】
- hihoCoder 1236 Scores 五维偏序 (分块 + bitset)
- hihocoder #1236 : Scores
- [LeetCode]Rank Scores,解题报告
- [LeetCode]Rank Scores,解题报告
- [五维偏序 分块 bitset] HihoCoder #1236 2015北京网络赛 J Scores
- hihocoder#1039 解题报告
- [hihoCoder] 岛屿 解题报告
- hiho 1236 Scores 五维偏序 分块+bitset优化
- hihocoder 1236 (分块+bitset乱搞)
- hihoCoder 1236 bitset + 分块
- BZOJ 3687 bitset 解题报告
- UVa1588——Kickdown
- 鸟哥的Linux私房菜10.13 档案与目录管理
- “工业4.0”战略引擎!揭开神秘的量子点技术
- android traceview的使用
- 计算几何(凸包模版,向量运算)
- hihoCoder 1236 Scores 解题报告(bitset + 分段暴力)
- Android LayoutInflater用法
- 探索Ionic过程中的一些亮点与各种坑整理
- NSAttributedString的各种设置
- RichEdit的复制与粘贴
- Report View 2008 升级至Report View 2012
- ExecutorService对象的shutdown()和shutdownNow()的区别
- shell笔记
- 2015我想和Java聊聊之NIO读写文件