이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#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;
void phongbeo();
const int inf=1e18;
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
}
vector<int> v[200007],v2[200007];
vector<ib> v3[200007];
int ans[200001];
struct lz{
int b,c;
};
int a[200001];
ib b[100001];
struct IT
{ ic t[800001];
lz lazy[400001];
void build(int node,int l,int r)
{ t[node]={-1,-inf,inf};
lazy[node]={inf,-inf};
if(l==r) return;
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
}
void ff(int x)
{
for(int i=x*2;i<=x*2+1;i++)
{
t[i].a=max({t[i].a,lazy[x].c-t[i].c,t[i].b-lazy[x].b});
lazy[i].b=min(lazy[i].b,lazy[x].b);
lazy[i].c=max(lazy[i].c,lazy[x].c);
}
lazy[x]={inf,-inf};
}
void upd(int node,int l,int r,int l1,int c)
{ ///if(l1==2) cout<<l<<" "<<r<<" "<<c<<" "<<t[node].a,down
if(l==r)
{
if(!c)t[node]={t[node].a,-inf,inf};
else t[node]={t[node].a,a[l],a[l]};
///if(l1==2) cout<<t[node].a<<" cucu",down
return;
}
int mid=l+r>>1;
ff(node);
if(l1<=mid) upd(node<<1,l,mid,l1,c);
else upd(node<<1|1,mid+1,r,l1,c);
t[node].b=max(t[node<<1].b,t[node<<1|1].b);
t[node].c=min(t[node<<1].c,t[node<<1|1].c);
t[node].a=max(t[node<<1].a,t[node<<1|1].a);
}
void upd2(int node,int l,int r,int l1,int r1,int x)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1)
{
t[node].a=max({t[node].a,x-t[node].c,t[node].b-x});
lazy[node].b=min(lazy[node].b,x);
lazy[node].c=max(lazy[node].c,x);
return;
}
ff(node);
int mid=l+r>>1;
upd2(node<<1,l,mid,l1,r1,x);
upd2(node<<1|1,mid+1,r,l1,r1,x);
t[node].a=max(t[node<<1].a,t[node<<1|1].a);
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return -1;
if(l>=l1&&r<=r1) return t[node].a;
int mid=l+r>>1;
ff(node);
return max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
}st;
void phongbeo()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>l>>r;
v[i+l].pb(i);
if(i+r+1<=n)v2[r+i+1].pb(i);
b[i]={l,r};
}
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>l>>r;
v3[r].pb({l,i});
}
st.build(1,1,n);
for(int i=1;i<=n;i++)
{
for(auto x:v[i])
{
st.upd(1,1,n,x,1);
}
for(auto x:v2[i])
{
st.upd(1,1,n,x,0);
}
if(i-b[i].a>=1){
st.upd2(1,1,n,max(1ll,i-b[i].b),i-b[i].a,a[i]);
}
for(auto x:v3[i])
ans[x.b]=st.get(1,1,n,x.a,i);
}
for(int i=1;i<=m;i++)
cout<<ans[i],down
}
컴파일 시 표준 에러 (stderr) 메시지
antennas.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main()
| ^~~~
antennas.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
antennas.cpp:73:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int mid=l+r>>1;
| ~^~
antennas.cpp: In member function 'void IT::upd(long long int, long long int, long long int, long long int, long long int)':
antennas.cpp:96:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int mid=l+r>>1;
| ~^~
antennas.cpp: In member function 'void IT::upd2(long long int, long long int, long long int, long long int, long long int, long long int)':
antennas.cpp:115:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
115 | int mid=l+r>>1;
| ~^~
antennas.cpp: In member function 'long long int IT::get(long long int, long long int, long long int, long long int, long long int)':
antennas.cpp:124:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
124 | int mid=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |