QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236239 | #7520. Monster Generator | ExplodingKonjac | WA | 0ms | 3824kb | C++20 | 7.8kb | 2023-11-03 18:57:03 | 2023-11-04 18:37:28 |
Judging History
你现在查看的是最新测评结果
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-11-03 18:57:03]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
public:
FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
~FastOutput() { flush(); }
void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
void put(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
FastOutput &operator <<(char x)
{ return put(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;put(*(s++)));return *this; }
FastOutput &operator <<(const std::string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(T x)
{
if(x<0) return put('-'),(*this)<<(-x);
char stk[numeric_limits<T>::digits10+1],*top=stk;
do *(top++)=x%10+'0',x/=10; while(x);
while(top!=stk) put(*(--top));
return *this;
}
template<typename ...T>
void writesp(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put(' '),0)...}; }
template<typename ...T>
void writeln(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put('\n'),0)...}; }
template<typename Iter>
void writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
void writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
private:
bool __eof;
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char get()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void unget(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf[--buf_p]=c;
#else
ungetc(c,target);
#endif
}
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=get()));return *this; }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=get()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=get();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
return unget(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=get()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=get());
return unget(*s),*s='\0',*this;
}
FastInput &operator >>(std::string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=get()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
unget(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &&...x)
{ std::initializer_list<int>{((*this)>>(x),0)...}; }
template<typename Iter>
void read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
using I128=__int128_t;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) [](auto...){}(__VA_ARGS__)
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace Math
{
// A class for 2D vectors.
template<typename T>
struct Vector2d
{
T x,y;
Vector2d(): x(),y() {}
Vector2d(const T &_x,const T &_y): x(_x),y(_y) {}
#define DEF_OP1(op) \
Vector2d &operator op##=(const Vector2d &rhs) \
{ return x op##= rhs.x,y op##= rhs.y,*this; } \
Vector2d operator op(const Vector2d &rhs)const \
{ return Vector2d(*this)op##=rhs; }
DEF_OP1(+) DEF_OP1(-) DEF_OP1(*) DEF_OP1(/)
#undef DEF_OP1
template<typename U>
Vector2d &operator *=(U scale)
{ return x*=scale,y*=scale,*this; }
template<typename U>
Vector2d &operator /=(U scale)
{ return x/=scale,y/=scale,*this; }
template<typename U>
friend Vector2d operator *(U scale,const Vector2d &u)
{ return Vector2d(u)*=scale; }
template<typename U>
friend Vector2d operator *(const Vector2d &u,U scale)
{ return Vector2d(u)*=scale; }
template<typename U>
friend Vector2d operator /(const Vector2d &u,U scale)
{ return Vector2d(u)/=scale; }
auto proj(const Vector2d &u)const
{ return (*this)*(dot(u,*this)/abs2(*this)); }
template<typename U>
auto trunc(U r)const
{ auto l=abs(*this);return l?(*this)*(r/l):*this; }
template<typename U>
auto rotate(U t)const
{ auto c=std::cos(t),s=std::sin(t);return Vector2d(x*c-y*s,x*s+y*c); }
bool operator <(const Vector2d &rhs)const
{ return x!=rhs.x?x<rhs.x:y<rhs.y; }
bool operator ==(const Vector2d &rhs)const
{ return x==rhs.x && y==rhs.y; }
bool operator !=(const Vector2d &rhs)const
{ return x!=rhs.x && y!=rhs.y; }
};
template<typename T>
auto cross(const Vector2d<T> &u,const Vector2d<T> &v)
{ return u.x*v.y-u.y*v.x; }
template<typename T>
auto dot(const Vector2d<T> &u,const Vector2d<T> &v)
{ return u.x*v.x+u.y*v.y; }
template<typename T>
auto abs(const Vector2d<T> &u)
{ return std::hypot(u.x,u.y); }
template<typename T>
auto abs2(const Vector2d<T> &u)
{ return u.x*u.x+u.y*u.y; }
template<typename T>
auto arg(const Vector2d<T> &u)
{ return std::atan2(u.y,u.x); }
} // namespace Math
using ZVec=Math::Vector2d<LL>;
int n,nn;
LL m,lsh[100005];
struct Monster{ LL a,da,b,db; }a[105];
inline LL calc(LL k1,LL b1,LL k2,LL b2)
{
if(k1==k2) return -1;
if(k1<k2) swap(k1,k2),swap(b1,b2);
k1=k1-k2,b1=b2-b1;
if(b1<0) return -(-b1)/k1;
else return (b1+k1-1)/k1;
}
int main()
{
qin>>n>>m;
for(int i=1;i<=n;i++)
qin>>a[i].a>>a[i].da>>a[i].b>>a[i].db;
lsh[++nn]=0,lsh[++nn]=m+1;
auto add=[&](LL x) {
if(x>0 && x<=m) lsh[++nn]=x;
};
for(int i=1;i<=n;i++)
{
add(calc(a[i].da,a[i].a,a[i].db,a[i].b));
for(int j=i+1;j<=n;j++)
{
add(calc(a[i].da,a[i].a,a[j].da,a[j].a));
add(calc(a[i].db,a[i].b,a[j].db,a[j].b));
}
}
sort(lsh+1,lsh+nn+1);
nn=unique(lsh+1,lsh+nn+1)-lsh-1;
ULL ans=0;
for(int t=1;t<nn;t++)
{
LL vl=lsh[t],vr=lsh[t+1]-1;
sort(a+1,a+n+1,[&](auto &lhs,auto &rhs) {
I128 al=lhs.a+(I128)lhs.da*vl,bl=lhs.b+(I128)lhs.db*vl;
I128 ar=rhs.a+(I128)rhs.da*vl,br=rhs.b+(I128)rhs.db*vl;
if(al<=bl && ar<=br) return al<ar;
else if(al>bl && ar>br) return bl>br;
else return al<=bl;
});
vector<pair<LL,LL>> vec{{0,0}};
for(LL i=1,k=0,b=0;i<=n;i++)
{
k+=a[i].da-a[i-1].db;
b+=a[i].a-a[i-1].b;
vec.emplace_back(k,b);
}
sort(vec.begin(),vec.end(),[](auto &lhs,auto &rhs) {
if(lhs.first==rhs.first)
return lhs.second<rhs.second;
return lhs.first<rhs.first;
});
stack<pair<int,LL>> st;
for(int i=0;i<(int)vec.size();i++)
{
auto &[k,b]=vec[i];
LL lst=0;
while(!st.empty())
{
auto [id,pos]=st.top();
lst=max(0ll,calc(vec[id].first,vec[id].second,k,b));
if(lst>pos) break;
else st.pop();
}
st.emplace(i,st.empty()?0:lst);
}
LL lst=m+1;
while(!st.empty())
{
auto [id,pos]=st.top();
LL l=max(pos,vl),r=min(lst-1,vr);
if(l<=r)
ans+=vec[id].first*ULL(I128(l+r)*(r-l+1)/2)
+vec[id].second*ULL(r-l+1);
lst=pos,st.pop();
}
}
qout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 100000000 3 1 5 2 4 2 1 3 1 9 100 1
output:
35000000549999998
result:
ok single line: '35000000549999998'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
10 1000000000000000000 776874380544333 197 471391764744275 33 159838820333814 107 677112662750393 41 962335658276824 48 255593531071176 11 127404116579775 209 268525254990127 34 647620110614714 76 897947476313307 13 146196843402516 221 772928712898807 39 637929916804442 2 716937021892338 15 64200226...
output:
17883317185357051350
result:
ok single line: '17883317185357051350'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
10 1000000000000 519946 5 967590 4 367668 9 772494 6 635694 5 932710 1 260259 2 627580 1 84994 3 52124 6 447095 4 705749 6 427312 2 977458 7 540121 1 292993 5 556831 6 321679 4 567919 4 609512 4
output:
1542003553990731211
result:
wrong answer 1st lines differ - expected: '1542003553318518337', found: '1542003553990731211'