# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
288871 | mohammedehab2002 | Constellation 3 (JOI20_constellation3) | C++11 | 1590 ms | 28536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long w[200005],ans;
vector<int> v[200005];
pair<pair<int,int>,int> s[200005];
int a[200005],pre[200005],nex[200005];
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+w[s[i].first.second];
if (v>0)
{
ans-=v;
for (int j=pre[i];j<=nex[i];j++)
w[j]-=v;
}
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |