이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long tree[800005],ans;
vector<int> v[200005];
pair<pair<int,int>,int> s[200005];
int a[200005],pre[200005],nex[200005];
void update(int node,int st,int en,int l,int r,long long v)
{
if (en<l || st>r || r<l)
return;
if (l<=st && en<=r)
{
tree[node]-=v;
return;
}
int mid=(st+en)/2;
update(2*node,st,mid,l,r,v);
update(2*node+1,mid+1,en,l,r,v);
}
long long query(int node,int st,int en,int idx)
{
long long ret=tree[node];
if (st!=en)
{
int mid=(st+en)/2;
if (st<=idx && idx<=mid)
ret+=query(2*node,st,mid,idx);
else
ret+=query(2*node+1,mid+1,en,idx);
}
return ret;
}
int main()
{
int n,m;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]=n-a[i];
}
scanf("%d",&m);
for (int i=0;i<m;i++)
{
scanf("%d%d%d",&s[i].first.second,&s[i].first.first,&s[i].second);
s[i].first.first=n-s[i].first.first+1;
ans+=s[i].second;
}
sort(s,s+m);
reverse(s,s+m);
for (int i=0;i<m;i++)
v[s[i].first.second].push_back(i);
stack<int> st;
set<pair<int,int> > idx;
st.push(0);
idx.insert({0,0});
for (int i=1;i<=n;i++)
{
while (!st.empty() && a[i]<=a[st.top()])
{
idx.erase({a[st.top()],st.top()});
st.pop();
}
for (int j:v[i])
pre[j]=(*prev(idx.upper_bound({s[j].first.first,-1}))).second+1;
st.push(i);
idx.insert({a[i],i});
}
while (!st.empty())
st.pop();
idx.clear();
st.push(n+1);
idx.insert({0,n+1});
for (int i=n;i>0;i--)
{
while (!st.empty() && a[i]<=a[st.top()])
{
idx.erase({a[st.top()],st.top()});
st.pop();
}
for (int j:v[i])
nex[j]=(*prev(idx.upper_bound({s[j].first.first,-1}))).second-1;
st.push(i);
idx.insert({a[i],i});
}
for (int i=0;i<m;i++)
{
long long v=s[i].second+query(1,1,n,s[i].first.second);
if (v>0)
{
ans-=v;
update(1,1,n,pre[i],nex[i],v);
}
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
constellation3.cpp: In function 'int main()':
constellation3.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
36 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
constellation3.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
constellation3.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
42 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
constellation3.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
45 | scanf("%d%d%d",&s[i].first.second,&s[i].first.first,&s[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |