HDU 5808 Price List Strike Back
来源:互联网 发布:北航软件工程硕士学费 编辑:程序博客网 时间:2024/04/26 11:56
Problem Description
There are n shops numbered with successive integers from 1 to n in Byteland. Every shop sells only one kind of goods, and the price of the i -th shop's goods is vi . The distance between the i -th shop and Byteasar's home is di .
Every day, Byteasar will purchase some goods. On thei -th day, he will choose an interval [li,ri] and an upper limit ci . Then, he will visit each shop with distance at most ci away from home in [li,ri] , buy at most one piece of goods from each shop and go back home. Of course, he can also choose to buy nothing. Back home, Byteasar will calculate the total amount of money he has costed that day and write it down on his account book, denoted as sumi .
However, due to Byteasar's poor math, he may calculate it wrong.
Please write a program to help Byteasar judge whether each number is sure to be calculated wrong.
Every day, Byteasar will purchase some goods. On the
However, due to Byteasar's poor math, he may calculate it wrong.
Please write a program to help Byteasar judge whether each number is sure to be calculated wrong.
Input
The first line of the input contains an integer T (1≤T≤10) , denoting the number of test cases.
In each test case, the first line of the input contains two integersn,m (1≤n≤20000,1≤m≤100000) , denoting the number of shops and the number of records on Byteasar's account book.
The second line of the input containsn integers v1,v2,...,vn (1≤vi≤100) , denoting the price of the i -th shop's goods.
The third line of the input containsn integers d1,d2,...,dn (1≤di≤109) , denoting the distance between the i -th shop and Byteasar's home.
Each of the nextm lines contains four integers li,ri,ci,sumi (1≤li≤ri≤n,1≤ci≤109,1≤sumi≤100) , denoting a record on Byteasar's account book.
In each test case, the first line of the input contains two integers
The second line of the input contains
The third line of the input contains
Each of the next
Output
For each test case, print a line with m characters. If the i -th number is sure to be calculated wrong, then the i -th character should be '1'. Otherwise, it should be '0'.
Sample Input
23 33 3 32 4 33 3 5 33 3 3 12 3 1 35 45 1 2 4 21 8 9 2 11 5 1 34 4 1 51 5 3 51 3 5 1
Sample Output
0111101
标算的做法,分治,复杂度100(nlogn+m)+mlogn
#include<set>#include<map>#include<ctime>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef __int64 LL;const int low(int x) { return x&-x; }const double eps = 1e-8;const int INF = 0x7FFFFFFF;const int mod = 998244353;const int N = 2e4 + 10;const int M = 1e5 + 10;int T, n, m, x;int v[N], d[N], f[N][101];int l[M], r[M], c[M], s[M], ans[M], a[M], b[M];void solve(int L, int R, int ll, int rr){ if (ll > rr) return; if (L == R) { rep(i, ll, rr) ans[a[i]] = v[R] == s[a[i]] && d[R] <= c[a[i]]; } else { int mid = L + R >> 1, w1 = ll, w2 = rr, w3 = 0; rep(i, ll, rr) { if (r[a[i]] <= mid) a[w1++] = a[i]; else if (l[a[i]] > mid) b[w2--] = a[i]; else b[w3++] = a[i]; } rep(i, w2 + 1, rr) a[i] = b[i]; if (w3) { rep(i, 1, 100) f[mid][i] = f[mid + 1][i] = INF; f[mid][0] = f[mid + 1][0] = 0; f[mid][v[mid]] = d[mid]; f[mid + 1][v[mid + 1]] = d[mid + 1]; per(i, mid - 1, L) { per(j, 100, v[i]) f[i][j] = min(f[i + 1][j], max(f[i + 1][j - v[i]], d[i])); per(j, v[i] - 1, 0) f[i][j] = f[i + 1][j]; } rep(i, mid + 2, R) { rep(j, v[i], 100) f[i][j] = min(f[i - 1][j], max(f[i - 1][j - v[i]], d[i])); rep(j, 0, v[i] - 1) f[i][j] = f[i - 1][j]; } } rep(i, 0, w3 - 1) { rep(j, 0, s[b[i]]) ans[b[i]] |= max(f[l[b[i]]][j], f[r[b[i]]][s[b[i]] - j]) <= c[b[i]]; } solve(L, mid, ll, w1 - 1); solve(mid + 1, R, w2 + 1, rr); }}int main(){ scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); rep(i, 1, n) scanf("%d", &v[i]); rep(i, 1, n) scanf("%d", &d[i]); rep(i, 1, m) a[i] = i, ans[i] = 0; rep(i, 1, m) scanf("%d%d%d%d", &l[i], &r[i], &c[i], &s[i]); solve(1, n, 1, m); rep(i, 1, m) printf("%d", ans[i] ^ 1); putchar(10); } return 0;}
树状数组+多重背包二进制优化,按道理来说复杂度要炸,然而实际上跑的比分治还快。#include<set>#include<map>#include<ctime>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef __int64 LL;const int low(int x) { return x&-x; }const double eps = 1e-8;const int INF = 0x7FFFFFFF;const int mod = 998244353;const int N = 2e4 + 10;const int M = 1e5 + 10;int T, n, m, x, y, q, p;int v[N], d[N], f[101][N];int l[M], r[M], c[M], s[M], ans[M];int a[N], b[M], dp[101];bool cmp1(const int &x, const int &y){ return d[x] < d[y];}bool cmp2(const int &x, const int &y){ return c[x] < c[y];}void insert(int x, int y){ if (x > p) return; for (int i = y; i <= q; i += low(i)) f[x][i]++;}int get(int x, int y){ if (x > p) return 0; int res = 0; for (int i = y; i; i -= low(i)) res += f[x][i]; return res;}int main(){ scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); x = y = q = 0; rep(i, 1, n) scanf("%d", &v[i]), x = max(x, v[i]); rep(i, 1, n) scanf("%d", &d[i]), a[i] = i; rep(i, 1, m) { scanf("%d%d%d%d", &l[i], &r[i], &c[i], &s[i]); b[i] = i; y = max(y, s[i]); q = max(q, r[i]); } p = min(x, y); rep(i, 1, p) rep(j, 1, q) f[i][j] = 0; sort(a + 1, a + n + 1, cmp1); sort(b + 1, b + m + 1, cmp2); for (int i = 1, j = 1; i <= m; i++) { for (; j <= n&&d[a[j]] <= c[b[i]]; j++) insert(v[a[j]], a[j]); int S = s[b[i]], L = l[b[i]], R = r[b[i]]; if (ans[b[i]] = get(S, R) - get(S, L - 1)) continue; rep(k, 1, S) dp[k] = 0; dp[0] = 1; for (int k = 1; !dp[S] && k < S; k++) { x = min(S / k, get(k, R) - get(k, L - 1)); for (y = 1; !dp[S] && x; x -= min(x, y), y <<= 1) { int cost = min(x, y)*k; for (int w = S; !dp[S] && w >= cost; w--) dp[w] |= dp[w - cost]; } } ans[b[i]] = dp[S]; } rep(i, 1, m) printf("%d", ans[i] ? 0 : 1); putchar(10); } return 0;}
0 0
- HDU 5808 Price List Strike Back
- hdu 5808 Price List Strike Back 分治
- HDU 5808 Price List Strike Back
- HDU 5808 Price List Strike Back(整体二分)
- HDU 5808Price List Strike Back (cdq 分治)
- HDU 5808Price List Strike Back cdq分治+背包
- HDU5808 Price List Strike Back
- HDU 5808 BestCoder Round #86 Price List Strike Back (树状数组)
- Hdu 5808 Price List Strike Back(分治,BestCoder Round #86 E)
- HDU5808(Bestcoder Round86)Price List Strike Back
- BestCoder#86 E / hdu5808 Price List Strike Back
- strike back
- hdu Price List
- HDU 5804:Price List
- hdu 5804 Price List
- HDU 5804 Price List
- HDU 5804 Price List
- HDU 5804 Price List
- 如何查找电脑ip
- DWR搭建以及使用教程
- ListView 滑动监听的几种状态
- 温故知新
- 数据统计_百度统计
- HDU 5808 Price List Strike Back
- 剑指Offer: 二叉树的深度、平衡二叉树
- 【javase复习】## 网络编程 ##
- ThreadLocal的错误理解纠正
- Quartz(08) quartz spring web 项目的整合(方法二)
- wireshark学习总结(1)---有用的链接
- android studio sqlite一个基本操作
- 集训总结一
- httpURLConnection获得网络数据解析json串