This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
const int inf=1e9;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
//fin(task),fou(task);
#endif
NHP
/// cin>>s1;
// modwwe
phongbeo(),down
checktime
}
bool b[200001];
int a[200001];
int cc[200001];
ib d[200001];
ib dsu[200001];
void reset(int x)
{
dsu[x]= {1,x};
d[x]= {x,x};
}
int get(int x)
{
if(dsu[x].b!=x)dsu[x].b=get(dsu[x].b);
return dsu[x].b;
}
void noi(int x,int y)
{
x=get(x);
y=get(y);
if(x==y) return;
if(dsu[x].a<dsu[y].a) swap(x,y);
dsu[x].a+=dsu[y].a;
dsu[y].b=x;
d[x].a=min(d[x].a,d[y].a);
d[x].b=max(d[y].b,d[x].b);
}
struct cmp
{
bool operator()(ic a,ic b)
{
return a.a<b.a;
}
};
bool check(ic x)
{
auto [c, l, r] = x;
return !b[l] && !b[r] && (l == 0 || !b[l - 1]) && (r == n - 1 || !b[r + 1]);
}
void phongbeo()
{
cin>>n;
priority_queue<ic,vector<ic>,cmp>p;
for(int i=1; i<=n; i++)
cin>>a[i],p.push({a[i],i,i}),reset(i);
for(int i=1; i<=n; i++)
{
if(i%2==0)a[i]=-a[i];
cc[i]=cc[i-1]+a[i];
}
for(int i=1; i<=(n+1)/2; i++)
{
ic x=p.top();
while(!check(x)&&!p.empty())
{
//cout<<p.size(),down
p.pop();
x=p.top();
}
s2+=x.a;
cout<<s2,down
b[x.b]=1;
b[x.c]=1;
if(x.b-1>0) noi(x.b,x.b-1);
if(x.c+1<=n) noi(x.c,x.c+1);
s3=get(x.b);
s4=d[s3].a;
s5=d[s3].b;
if(s5%2==0)s6=-1;
else s6=1;
p.push({(cc[s5]-cc[s4-1])*s6,s4,s5});
}
}
Compilation message (stderr)
candies.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |