QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#55506 | #2103. Termity | ExplodingKonjac | WA | 2ms | 3748kb | C++17 | 4.1kb | 2022-10-14 10:42:23 | 2022-10-14 10:42:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<22;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
};
class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
protected:
inline void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
putc(x,target);
#endif
}
template<typename T>
inline void __write(T x)
{
static char stk[64],*top;top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
~FastOutput(){ flush(); }
#endif
template<typename ...T>
inline void writesp(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
inline void writeln(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
inline FastOutput &operator <<(char x)
{ return __putc(x),*this; }
inline FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
inline FastOutput &operator <<(const string &s)
{ return (*this)<<s.c_str(); }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastOutput &operator <<(const T &x)
{ return __write(x),*this; }
}qout;
class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
protected:
inline char __getc()
{
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
return buf[buf_p++];
#else
return getc(target);
#endif
}
public:
#ifdef OPENIOBUF
FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
inline char getchar() { return __getc(); }
template<typename ...T>
inline void read(T &...x)
{ initializer_list<int>{(this->operator>>(x),0)...}; }
inline FastInput &operator >>(char &x)
{ while(isspace(x=__getc()));return *this; }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastInput &operator >>(T &x)
{
static char ch,sym;x=sym=0;
while(isspace(ch=__getc()));
if(ch=='-') sym=1,ch=__getc();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
return sym?x=-x:x,*this;
}
inline FastInput &operator >>(char *s)
{
while(isspace(*s=__getc()));
for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
return *s='\0',*this;
}
inline FastInput &operator >>(string &s)
{
char str_buf[(1<<8)+1],*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=__getc()));
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
*p='\0',s.append(str_buf);
if(p!=buf_end) break;
}
return *this;
}
}qin;
}
using namespace FastIO;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
const LL INF=1e18;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif
LL n,sum,a[1000005];
vector<LL> vec;
void process(int l,int r)
{
static LL top,st[1000005];
for(int i=l;i<=r;i++)
{
LL x=a[i];
while(top>1 && st[top]>=x && st[top]>=st[top-1])
x+=st[top-1]-st[top],top-=2;
st[++top]=x;
}
while(top) vec.push_back(st[top--]);
}
int main()
{
qin>>n;
for(int i=1;i<=n;i++) qin>>a[i];
a[0]=a[n+1]=-INF,sum=accumulate(a+1,a+n+1,0ll);
for(int i=0,j=0;i<=n+1;i++,j++)
{
if(!a[i]) continue;
while(a[j]) j++;
process(i,--j),i=j;
}
sort(vec.begin(),vec.end(),greater<LL>());
LL tmp=0,fl=0;
for(auto &i: vec) (fl?tmp-=i:tmp+=i),fl^=1;
qout.writesp((sum+tmp)/2,(sum-tmp)/2);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3704kb
input:
1 0
output:
0 0
result:
ok single line: '0 0 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2 0 17
output:
17 0
result:
ok single line: '17 0 '
Test #3:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
3 0 13 0
output:
13 0
result:
ok single line: '13 0 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
8 1 2 0 3 7 4 0 9
output:
17 9
result:
ok single line: '17 9 '
Test #5:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
10 0 0 0 1 0 0 0 5 0 0
output:
5 1
result:
ok single line: '5 1 '
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 3500kb
input:
24 55 33 93 169 237 0 219 125 39 13 96 166 200 278 0 99 2 18 110 0 58 57 0 42
output:
1147 962
result:
wrong answer 1st lines differ - expected: '1125 984', found: '1147 962 '