提交记录 9961


用户 题目 状态 得分 用时 内存 语言 代码长度
czyarl noi17e. 【NOI2017】蔬菜 Accepted 100 137.829 ms 5104 KB C++ 3.10 KB
提交时间 评测时间
2019-07-30 13:11:11 2020-08-01 01:59:37
#include<bits/stdc++.h>
#define MAXN 100000
#define LL long long
using namespace std;
template<typename T>void Read(T &cn)
{
	char c;int sig = 1;
	while(!isdigit(c = getchar()))if(c == '-')sig = -1;cn = c-48;
	while(isdigit(c = getchar()))cn = cn*10+c-48;cn*=sig;
}
template<typename T>void Write(T cn)
{
	if(cn < 0) {putchar('-'); cn = 0-cn; }
	int wei = 0; T cm = 0; int cx = cn%10; cn/=10;
	while(cn)wei++,cm = cm*10+cn%10,cn/=10;
	while(wei--)putchar(cm%10+48),cm/=10;
	putchar(cx+48);
}
int n,m,k;
struct qwe{
	int a,s,x,c;
	int zui;
	inline friend bool operator <(qwe a,qwe b)
	{
		return a.zui > b.zui;
	}
	void getit() {Read(a); Read(s); Read(c); Read(x); zui = x ? (int)ceil((double)c/(double)x) : MAXN; zui = min(zui,MAXN); }
};
qwe a[MAXN+1];
int dui[MAXN+1];
int yong[MAXN+1];
int zhan[MAXN+1],zlen;
int Cmp1(int cn,int cm) {return a[cn].a + a[cn].s * (yong[cn] == 0) < a[cm].a + a[cm].s * (yong[cm] == 0); }
int Cmp2(int cn,int cm) {return a[cn].a + a[cn].s * (yong[cn] == 1) > a[cm].a + a[cm].s * (yong[cm] == 1); }
LL ans;
LL ans_p[MAXN+1];
int zong;
int sheng(int cn,int cm) {return a[cn].c - yong[cn] - 1ll*(cm-1) * (a[cn].x); }
signed main()
{
//	freopen("testdata_2.in","r",stdin);
//	freopen("testdata_2.ou","w",stdout);
	Read(n); Read(m); Read(k);
	for(int i = 1;i<=n;i++)a[i].getit();
	sort(a+1,a+n+1);
//	for(int i = 1;i<=n;i++)printf("a[%d].zui = %d a[%d].a = %d\n",i,a[i].zui,i,a[i].a);
	int dang = 0; ans = 0;
	int dlen = 0;
	memset(yong,0,sizeof(yong));
	for(int i = MAXN;i>=1;i--)
	{
		while(dang < n && a[dang+1].zui >= i)
		{
			dui[++dlen] = ++dang;
			push_heap(dui+1,dui+dlen+1,Cmp1);
		}
		int xian = 0;
		zlen = 0;
		while(xian < m && dlen)
		{
			int lin = dui[1];
//			if(i >= 200 && i<=260)printf("i = %d lin = %d %d %d\n",i,lin,Cmp1(2,4),sheng(lin,i));
			pop_heap(dui+1,dui+(dlen--)+1,Cmp1);
			if(!yong[lin]){
				yong[lin]++; xian++;
				ans = ans + a[lin].a + a[lin].s;
				dui[++dlen] = lin;
				push_heap(dui+1,dui+dlen+1,Cmp1);
			}
			else{
				zhan[++zlen] = lin;
				if(sheng(lin,i) <= 0)continue;
				int lin2 = min(sheng(lin,i),m-xian);
//				if(lin == 4)printf("lin2 = %d\n",lin2);
				ans = ans + 1ll*lin2 * a[lin].a;
				yong[lin] += lin2;
				xian += lin2;
			}
		}
		for(int j = 1;j<=zlen;j++) if(yong[zhan[j]] < a[zhan[j]].c) {dui[++dlen] = zhan[j]; push_heap(dui+1,dui+dlen+1,Cmp1);}
	}
	ans_p[MAXN] = ans;
	dlen = 0; zong = 0;
//	for(int i = 1;i<=n;i++)printf("yong[%d] = %d\n",i,yong[i]);
	for(int i = 1;i<=n;i++)zong += yong[i];
	for(int i = 1;i<=n;i++)if(yong[i])dui[++dlen] = i,push_heap(dui+1,dui+dlen+1,Cmp2);
	for(int i = MAXN-1;i>=1;i--)
	{
		while(zong > i*m)
		{
			int lin = dui[1]; pop_heap(dui+1,dui+(dlen--)+1,Cmp2);
			if(yong[lin] == 1){
				int lin2 = 1;
				int lin3 = a[lin].a + a[lin].s;
				ans = ans - 1ll*lin2 * lin3;
				yong[lin] -= lin2;
				zong -= lin2;
				continue;
			}
			int lin2 = min(yong[lin]-1,zong - i*m);
			int lin3 = a[lin].a;
			ans = ans - 1ll*lin2*lin3;
			yong[lin] -= lin2;
			zong -= lin2;
			dui[++dlen] = lin;
			push_heap(dui+1,dui+dlen+1,Cmp2);
		}
		ans_p[i] = ans;
	}
	for(int i = 1;i<=k;i++) {int bx; Read(bx); Write(ans_p[bx]); putchar('\n'); }
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1533.09 us1 MB + 204 KBAcceptedScore: 4

Testcase #2681.83 us1 MB + 208 KBAcceptedScore: 4

Testcase #3674.45 us1 MB + 208 KBAcceptedScore: 4

Testcase #4665.53 us1 MB + 220 KBAcceptedScore: 4

Testcase #5658.91 us1 MB + 220 KBAcceptedScore: 4

Testcase #6666.61 us1 MB + 220 KBAcceptedScore: 4

Testcase #7523.79 us1 MB + 196 KBAcceptedScore: 4

Testcase #8525.45 us1 MB + 196 KBAcceptedScore: 4

Testcase #9523.59 us1 MB + 196 KBAcceptedScore: 4

Testcase #10524.83 us1 MB + 196 KBAcceptedScore: 4

Testcase #11532.1 us1 MB + 196 KBAcceptedScore: 4

Testcase #12582.97 us1 MB + 204 KBAcceptedScore: 4

Testcase #13482.54 us1 MB + 204 KBAcceptedScore: 4

Testcase #14588.44 us1 MB + 204 KBAcceptedScore: 4

Testcase #15583.21 us1 MB + 204 KBAcceptedScore: 4

Testcase #161.097 ms1 MB + 232 KBAcceptedScore: 4

Testcase #171.174 ms1 MB + 232 KBAcceptedScore: 4

Testcase #181.147 ms1 MB + 232 KBAcceptedScore: 4

Testcase #191.225 ms1 MB + 232 KBAcceptedScore: 4

Testcase #201.219 ms1 MB + 232 KBAcceptedScore: 4

Testcase #21114.425 ms4 MB + 1000 KBAcceptedScore: 4

Testcase #2236.824 ms4 MB + 1008 KBAcceptedScore: 4

Testcase #23137.829 ms4 MB + 1004 KBAcceptedScore: 4

Testcase #2442.078 ms4 MB + 1008 KBAcceptedScore: 4

Testcase #2542.167 ms4 MB + 1008 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2020-10-29 18:49:57 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用