WA on test2 , 拍了一晚上了,求助
查看原帖
WA on test2 , 拍了一晚上了,求助
226485
柳苏明楼主2020/8/7 09:44

RT ,和第一篇题解对拍,到现在都没有拍出来,求大佬找一下错

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define R register int

namespace quick {
#define tp template<typename Type>
	namespace in {
		inline char getc() {
			static char buf[1<<21],*p1=buf,*p2=buf;
			return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
		}
		inline int read(char *s) {
			*s=getc();
			while(isspace(*s)) {*s=getc();if(*s==EOF) return 0;}
			while(!isspace(*s)&&*s!=EOF) {s++;*s=getc();}
			*s='\0'; return 1;
		}
		tp inline int read(Type &x) {
			x=0;bool k=false;char c=getc();
			while(!isdigit(c)) {k|=(c=='-');c=getc();if(c==EOF) return 0;}
			while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^48);c=getc();}
			x*=(k?-1:1); return 1;
		}
		template <typename Type,typename... Args>
		inline int read(Type &t,Args &...args) {
			int res=0;
			res+=read(t);res+=read(args...);
			return res;
		}
	}
	using in::read;
	namespace out {
		char buf[1<<21];int p1=-1;const int p2=(1<<21)-1;
		inline void flush() {
			fwrite(buf,1,p1+1,stdout);
			p1=-1;
		}
		inline void putc(const char &c) {
			if(p1==p2) flush();
			buf[++p1]=c;
		}
		inline void write(char *s) {
			while(*s!='\0') putc(*s),s++;
		}
		inline void write(const char *s) {
			while(*s!='\0') putc(*s),s++;
		}
		tp inline void write(Type x) {
			static char buf[30];int p=-1;
			if(x<0) {putc('-');x=-x;}
			if(x==0) putc('0');
			else for(;x;x/=10) buf[++p]=x%10+48;
			for(;p!=-1;p--) putc(buf[p]);
		}
		inline void write(const char &c) {putc(c);}
		template <typename Type,typename... Args>
		inline void write(Type t,Args ...args) {
			write(t);write(args...);
		}
	}
	using out::write;
	using out::flush;
	tp inline Type max(const Type &a,const Type &b) {
		if(a<b) return b;
		return a;
	}
	tp inline Type min(const Type &a,const Type &b) {
		if(a<b) return a;
		return b;
	}
	tp inline void swap(Type &a,Type &b) {
		a^=b^=a^=b;
	}
	tp inline Type abs(const Type &a) {
		return a>=0?a:-a;
	}
#undef tp
}
using namespace quick;

typedef long long ll;
const int maxn=1e5+20,maxm=1e2+20,inf=0x3f3f3f3f;
int n,m,p;
ll d[maxn],h[maxn],t[maxn];
ll a[maxn],s[maxn];
ll f[maxn][maxm];

#define X(var) ((double)(var))
#define Y(var) ((double)(f[i-1][var]+s[var]))
#define slope(u,v) ((double)((Y(v)-Y(u))/(X(v)-X(u))))

int main(void) {
#ifndef ONLINE_JUDGE
	freopen("cat.in","r",stdin);
#endif
	read(n,m,p);
	for(R i(2);i<=n;i++) read(d[i]),d[i]+=d[i-1];
	for(R i(1);i<=m;i++) read(h[i],t[i]);
	for(R i(1);i<=m;i++) a[i]=t[i]-d[h[i]];
	std::sort(a+1,a+1+m);
	for(R i(1);i<=m;i++) s[i]=s[i-1]+a[i];
	for(R i(1);i<=m;i++) f[1][i]=i*a[i]-s[i];
	for(R i(2);i<=p;i++) {
		static int q[maxn],tail,head;
		q[0]=0;head=tail=0;
		for(R j(1);j<=m;j++) {
			while(head<tail&&slope(q[head],q[head+1])<=(double)a[j]) head++;
			f[i][j]=(ll)f[i-1][q[head]]-s[j]+s[q[head]]+(j-q[head])*a[j];
			while(head<tail&&slope(q[tail],q[tail-1])>=slope(q[tail-1],j)) tail--;
			q[++tail]=j;
		}
	}
	write(f[p][m],'\n');
	flush();
	return 0;
}

#undef X
#undef Y
#undef slope

附写的垃圾数据生成器

import random
n=random.randint(1,100)
m=random.randint(1,100)
q=random.randint(1,m-1)
print(n,m,q)
for i in range (1,n) : 
	print(random.randint(1,100),end=' ')
print('')
for i in range (1,m+1) :
	print(random.randint(1,100),random.randint(1,100))

2020/8/7 09:44
加载中...