QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194532#7520. Monster Generatorucup-team159#WA 0ms3844kbC++236.0kb2023-09-30 20:59:592023-11-04 17:09:52

Judging History

你现在查看的是测评时间为 2023-11-04 17:09:52 的历史记录

  • [2023-11-04 18:36:34]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:0ms
  • 内存:3476kb
  • [2023-11-04 17:09:52]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:3844kb
  • [2023-09-30 21:00:01]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3620kb
  • [2023-09-30 20:59:59]
  • 提交

answer

// #pragma GCC target("avx,avx2")
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}

using Int = __int128;
using P = pair<Int,Int>;

istream& operator>>(istream& i, Int& x){
	x=0;
	string s;
	i>>s;
	int N=s.size(),it=0;
	if(s[0]=='-') it++;
	for(;it<N;it++) x=(x*10+s[it]-'0');
	if(s[0]=='-') x=-x;
	return i;
}
ostream& operator<<(ostream& o, const Int& x){
	Int tmp=x;
	if(tmp==0) return o<<0;
	if(tmp<0) o<<'-',tmp=-tmp;
	vector<int> ds;
	while(tmp) ds.pb(tmp%10),tmp/=10;
	reverse(all(ds));
	for(int d:ds) o<<d;
	return o;
}

struct Waf{
	Int a,da,b,db;
	Waf(Int a_,Int da_,Int b_,Int db_):a(a_),da(da_),b(b_),db(db_){}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; Int M; cin >> N >> M; M++;

	V<Waf> A;
	rep(i,N){
		Int a,da,b,db; cin >> a >> da >> b >> db;
		A.eb(a,da,b,db);
	}
	V<Int> xs; xs.pb(0);	// [xs[i],xs[i+1])
	{
		//sgn(-a+b)
		rep(i,N){
			auto w = A[i];
			Int p = w.db-w.da, q = w.b-w.a;
			if(p) xs.pb(divCeil(-q,p));
		}
		rep(i,N) rep(j,i){
			Int p = A[i].da-A[j].da, q = A[i].a-A[j].a;
			if(p) xs.pb(divCeil(-q,p));
		}
		rep(i,N) rep(j,i){
			Int p = A[i].db-A[j].db, q = A[i].b-A[j].b;
			if(p) xs.pb(divCeil(-q,p));
		}
	}
	xs.pb(M);
	// rep(i,M) xs.pb(i);
	{
		mkuni(xs);
		V<Int> nxs;
		for(Int x: xs) if(x >= 0 and x <= M) nxs.pb(x);
		xs = nxs;
	}
	show(xs);

	auto Lwin = [&](Waf l, Waf r, Int x){
		Int la = l.a+l.da*x, lb = l.b+l.db*x;
		Int ra = r.a+r.da*x, rb = r.b+r.db*x;
		if((-la+lb >= 0) != (-ra+rb >= 0)){
			return (-la+lb >= 0);
		}
		if(-la+lb >= 0) return la < ra;
		return lb > rb;
	};

	uint ans = 0;
	rep(t,si(xs)-1){
		Int xl = xs[t], xr = xs[t+1];
		sort(all(A),[&](Waf l,Waf r){
			return Lwin(l,r,xl);
		});
		V<P> pq(N);
		{
			Int p = 0, q = 0;	// px+q
			rep(i,N){
				const auto& w = A[i];
				p -= w.da, q -= w.a; shows(-p,-q);
				pq[i] = P(p,q);
				p += w.db, q += w.b; shows(p,q);
			}
		}
		// for(Int x=xl;x<xr;x++){	// brute
		// 	Int mn = 0;
		// 	rep(i,N){
		// 		Int tmp = pq[i].fs*x + pq[i].sc;
		// 		chmin(mn,tmp);
		// 	}
		// 	ans -= mn;
		// }
		sort(all(pq),[&](P l,P r){return l.fs > r.fs;});

		// OVERFLOW!!!!
		auto sgn = [&](Int x) -> int {
			if(x>0) return 1;
			if(x==0) return 0;
			return -1;
		};
		auto check = [&](P& a,P& b,P& c) -> bool {
			// return (b.fs-a.fs)*(c.sc-b.sc)>=(b.sc-a.sc)*(c.fs-b.fs);
			Int e = b.fs-a.fs, f = c.sc-b.sc, g = b.sc-a.sc, h = c.fs-b.fs;
			if(sgn(e)*sgn(f) != sgn(g)*sgn(h)){
				return sgn(e)*sgn(f) > sgn(g)*sgn(h);
			}
			if(sgn(e)*sgn(f) == 0) return true;
			bool inv = (sgn(e)*sgn(f) == -1);
			e = max(e,-e), f = max(f,-f), g = max(g,-g), h = max(h,-h);
			if(e/g != h/f) return inv ^ (e/g > h/f);
			e%=g, h%=f;
			return inv ^ (e*f >= g*h);
			// return ef >= gh
			// return e/g >= h/f
		};
		vector<P> cht;
		for(auto w: pq){
			while(si(cht)>=2 && check(cht[si(cht)-2],cht[si(cht)-1],w)) cht.pop_back();
			cht.pb(w);
		}
		V<Int> ys; ys.pb(xl);
		rep(i,si(cht)-1){
			// cht[i].fs * x + cht[i].sc vs [i+1]
			Int p = cht[i].fs-cht[i+1].fs, q = cht[i].sc-cht[i+1].sc;
			if(p) ys.pb(divCeil(-q,p));
		}
		ys.pb(xr);
		mkuni(ys);
		{
			V<Int> nys;
			for(Int y: ys) if(xl <= y && y <= xr) nys.pb(y);
			ys = nys;
		}
		int i = 0;
		auto eval = [&](P& a, Int x){
			return a.fs*x + a.sc;
		};
		auto Rgood = [&](P& a,P& b,Int x){
			return eval(a,x) >= eval(b,x);
		};
		rep(tt,si(ys)-1){
			Int yl = ys[tt], yr = ys[tt+1];
			while(i+1 < si(cht) && Rgood(cht[i],cht[i+1],yl)) i++;
			Int p = cht[i].fs, q = cht[i].sc;
			// px + q for [yl,yr)
			if((yr-yl)&1) ans += (yr-yl) * ((yl+yr-1) / 2) * p;
			else ans += (yr-yl)/2 * (yl+yr-1) * p;
			ans += (yr-yl) * q;
		}
	}
	ans = -ans;
	cout << ans << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

3 5
3 1 5 2
4 2 1 3
1 9 100 1

output:

113

result:

ok single line: '113'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3664kb

input:

3 100000000
3 1 5 2
4 2 1 3
1 9 100 1

output:

2817250686

result:

wrong answer 1st lines differ - expected: '35000000549999998', found: '2817250686'