标签:
题意:50000个5维向量,50000次询问每一维都不大于某一向量的向量个数,强制在线。
思路:做完这题才知道bitset效率这么高,自己本地测试了下1s可以操作1010个bit,orz简单粗暴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #include "local.h" #endif #define X first #define Y second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define all(a) (a).begin(), (a).end() #define mset(a, x) memset(a, x, sizeof(a)) #define mcpy(a, b) memcpy(a, b, sizeof(a)) typedef long long ll; template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);} template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);} int k; struct Node { int a[5]; int id; void read() { for (int i = 0; i < 5; i ++) { scanf("%d", a + i); } } bool operator < (const Node &that) const { return a[k] < that.a[k]; } }; Node stu[1 << 16]; int r[5][1 << 16], id[5][1 << 16]; bitset<1 << 16> bs[5][1 << 8]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif // ONLINE_JUDGE int T, n, q, m; cin >> T; while (T --) { cin >> n >> m; for (int i = 0; i < n; i ++) { stu[i].read(); stu[i].id = i; } int L = sqrt(n + 0.5); for (int i = 0; i < 5; i ++) { k = i; sort(stu, stu + n); bitset<1 << 16> bbs; for (int j = 0; j < n; j ++) { r[i][j] = stu[j].a[i]; id[i][j] = stu[j].id; bbs[stu[j].id] = 1; if (j % L == L - 1 || j == n - 1) { bs[i][j / L] = bbs; } } } int lastans = 0; cin >> q; while (q --) { Node qry; qry.read(); bitset<1 << 16> ans; for (int i = 0; i < 5; i ++) { qry.a[i] ^= lastans; bitset<1 << 16> buf; int pos = upper_bound(r[i], r[i] + n, qry.a[i]) - r[i]; if (pos / L) buf = bs[i][pos / L - 1]; while (pos % L) buf[id[i][-- pos]] = 1; if (i) ans &= buf; else ans = buf; } printf("%d\n", lastans = ans.count()); } } return 0; } |
[hihoCoder1236 Scores 2015BeijingOnline]简单粗暴的分块+简单粗暴的bitset
标签:
原文地址:http://www.cnblogs.com/jklongint/p/4831283.html