이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,q,a[200005],lazy[1000005];
pair<ll,ll>mx[1000005],mn[1000005];
void build(ll node,ll l,ll r){
if(l==r){
if(a[l]%2==1){
mx[node].f=-1;
mx[node].s=a[l];
mn[node].f=LINF-1;
mn[node].s=a[l];
}else {
mx[node].f=a[l];
mx[node].s=-1;
mn[node].f=a[l];
mn[node].s=LINF-1;
}
return;
}
ll mid=(l+r)/2;
build(2*node,l,mid);
build(2*node+1,mid+1,r);
mx[node].f=max(mx[2*node].f,mx[2*node+1].f);
mx[node].s=max(mx[2*node].s,mx[2*node+1].s);
mn[node].f=min(mn[2*node].f,mn[2*node+1].f);
mn[node].s=min(mn[2*node].s,mn[2*node+1].s);
}
void update(ll node,ll l,ll r,ll st,ll dr,ll val){
if(l>r){
return;
}
if(r<st){
return;
}
if(l>dr){
return;
}
if(lazy[node]!=0){
ll x=lazy[node];
if(mx[node].f!=-1){
mx[node].f+=x;
}
if(mx[node].s!=-1){
mx[node].s+=x;
}
if(mn[node].f!=LINF-1){
mn[node].f+=x;
}
if(mn[node].s!=LINF-1){
mn[node].s+=x;
}
if(x%2==1){
swap(mn[node].f,mn[node].s);
swap(mx[node].f,mx[node].s);
}
if(l!=r){
lazy[2*node]+=x;
lazy[2*node+1]+=x;
}
lazy[node]=0;
}
if(st<=l&&r<=dr){
ll x=val;
if(mx[node].f!=-1){
mx[node].f+=x;
}
if(mx[node].s!=-1){
mx[node].s+=x;
}
if(mn[node].f!=LINF-1){
mn[node].f+=x;
}
if(mn[node].s!=LINF-1){
mn[node].s+=x;
}
if(x%2==1){
swap(mn[node].f,mn[node].s);
swap(mx[node].f,mx[node].s);
}
if(l!=r){
lazy[2*node]+=val;
lazy[2*node+1]+=val;
}
return;
}
ll mid=(l+r)/2;
update(2*node,l,mid,st,dr,val);
update(2*node+1,mid+1,r,st,dr,val);
mx[node].f=max(mx[2*node].f,mx[2*node+1].f);
mx[node].s=max(mx[2*node].s,mx[2*node+1].s);
mn[node].f=min(mn[2*node].f,mn[2*node+1].f);
mn[node].s=min(mn[2*node].s,mn[2*node+1].s);
}
ll query1(ll node,ll l,ll r,ll st,ll dr){
if(l>r){
return LINF-1;
}
if(l>dr){
return LINF-1;
}
if(r<st){
return LINF-1;
}
if(lazy[node]!=0){
ll x=lazy[node];
if(mx[node].f!=-1){
mx[node].f+=x;
}
if(mx[node].s!=-1){
mx[node].s+=x;
}
if(mn[node].f!=LINF-1){
mn[node].f+=x;
}
if(mn[node].s!=LINF-1){
mn[node].s+=x;
}
if(x%2==1){
swap(mn[node].f,mn[node].s);
swap(mx[node].f,mx[node].s);
}
if(l!=r){
lazy[2*node]+=x;
lazy[2*node+1]+=x;
}
lazy[node]=0;
}
if(st<=l&&r<=dr){
return mn[node].f;
}
ll mid=(l+r)/2;
return min(query1(2*node,l,mid,st,dr),query1(2*node+1,mid+1,r,st,dr));
}
ll query2(ll node,ll l,ll r,ll st,ll dr){
if(l>r){
return -1;
}
if(l>dr){
return -1;
}
if(r<st){
return -1;
}
if(lazy[node]!=0){
ll x=lazy[node];
if(mx[node].f!=-1){
mx[node].f+=x;
}
if(mx[node].s!=-1){
mx[node].s+=x;
}
if(mn[node].f!=LINF-1){
mn[node].f+=x;
}
if(mn[node].s!=LINF-1){
mn[node].s+=x;
}
if(x%2==1){
swap(mn[node].f,mn[node].s);
swap(mx[node].f,mx[node].s);
}
if(l!=r){
lazy[2*node]+=x;
lazy[2*node+1]+=x;
}
lazy[node]=0;
}
if(st<=l&&r<=dr){
return mx[node].s;
}
ll mid=(l+r)/2;
return max(query2(2*node,l,mid,st,dr),query2(2*node+1,mid+1,r,st,dr));
}
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
}
build(1,1,n);
cin>>q;
while(q--){
ll type;
cin>>type;
if(type==0){
ll l,r,val;
cin>>l>>r>>val;
update(1,1,n,l,r,val);
}else {
ll l,r;
cin>>l>>r;
ll s1=query1(1,1,n,l,r);
if(s1==LINF-1){
s1=-1;
}
cout<<s1<<' ';
s1=query2(1,1,n,l,r);
if(s1==0){
s1=-1;
}
cout<<s1<<endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |