Topic links
The main topic: There are now n items, the article I items have c[i], each purchase of the item I a need a[i] yuan, can get b[i] price.
There are m inquiries, each inquiry form such as: The x item is forbidden to buy, you have y yuan, you can get the maximum value is how much. Inquiries are independent of each other.
CDQ: Division of Treatment
Solve (L,r) indicates that the currently maintained DP array, the answer to the record is to remove the answer to the item outside [L,R]
Solve (L,MID), the DP array is transferred with an item in [Mid+1,r]. When l=r, all ban=l=r queries are together (check DP array for answers)
My Harvest: 233
#include <bits/stdc++.h> using namespace std;
const int n=611111,v=2111;
int n,m;
int t,head[n];
int c[n],limit[n],w[n];
int dp[15][v],ans[n];
struct que{int pos,val;
Que (int a=0,int b=0) {pos=a;val=b;
}}q[n]; struct Edge{int Pos,money,nex;}
E[n];
void Add (int u,int v,int W) {e[t].pos=v,e[t].money=w,e[t].nex=head[u],head[u]=t++;}
void Dynamic_pro (int *f,int x) {for (int i=0;i<c[x];i++) {int l=1,r=1;q[1]=que (0,f[i]);
for (int j=1;j*c[x]<= (1000-i); j + +) {while (l<=r&&q[r].val<=f[j*c[x]+i]-j*w[x]) r--;
Q[++r]=que (J,f[j*c[x]+i]-j*w[x]);
while (L<=r&&q[l].pos<j-limit[x]) l++;
F[j*c[x]+i]=max (F[j*c[x]+i],q[l].val+j*w[x]); }}} void solve (int l,int r,int d) {if (l==r) {for (int I=head[l];~i;i=e[i].nex) ans[e[i].pos]=dp[d-1][e[i
].money];
return;
} int mid= (L+R) >>1;
for (int i=0;i<v;i++) dp[d][i]=dp[d-1][i]; for (iNT i=mid+1;i<=r;i++) Dynamic_pro (dp[d],i);
Solve (l,mid,d+1);
for (int i=0;i<v;i++) dp[d][i]=dp[d-1][i];
for (int i=l;i<=mid;i++) Dynamic_pro (dp[d],i);
Solve (mid+1,r,d+1);
} void Work () {scanf ("%d", &m);
for (int i=1;i<=m;i++) {int b,c;scanf ("%d%d", &b,&c);
Add (B+1,I,C);
} solve (1,n,1);
for (int i=1;i<=m;i++) printf ("%d\n", Ans[i]);
} void Init () {memset (head,-1,sizeof (head));
scanf ("%d", &n);
for (int i=1;i<=n;i++) scanf ("%d%d%d", &c[i],&w[i],&limit[i]);
} int main () {init ();
Work ();
return 0; }