#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);
}
Compilation message
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);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
3 ms |
5120 KB |
Output is correct |
4 |
Correct |
3 ms |
5120 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
5120 KB |
Output is correct |
8 |
Correct |
3 ms |
5120 KB |
Output is correct |
9 |
Correct |
3 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
4 ms |
5120 KB |
Output is correct |
13 |
Correct |
4 ms |
5120 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
3 ms |
5120 KB |
Output is correct |
4 |
Correct |
3 ms |
5120 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
5120 KB |
Output is correct |
8 |
Correct |
3 ms |
5120 KB |
Output is correct |
9 |
Correct |
3 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
4 ms |
5120 KB |
Output is correct |
13 |
Correct |
4 ms |
5120 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
5 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
7 ms |
5120 KB |
Output is correct |
29 |
Correct |
5 ms |
5180 KB |
Output is correct |
30 |
Correct |
6 ms |
5120 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5248 KB |
Output is correct |
33 |
Correct |
6 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
8 ms |
5248 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
5 ms |
5120 KB |
Output is correct |
38 |
Correct |
5 ms |
5248 KB |
Output is correct |
39 |
Correct |
6 ms |
5120 KB |
Output is correct |
40 |
Correct |
6 ms |
5248 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
5 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5248 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
3 ms |
5120 KB |
Output is correct |
4 |
Correct |
3 ms |
5120 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
5120 KB |
Output is correct |
8 |
Correct |
3 ms |
5120 KB |
Output is correct |
9 |
Correct |
3 ms |
5120 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
4 ms |
5120 KB |
Output is correct |
13 |
Correct |
4 ms |
5120 KB |
Output is correct |
14 |
Correct |
4 ms |
5120 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5120 KB |
Output is correct |
24 |
Correct |
5 ms |
5120 KB |
Output is correct |
25 |
Correct |
5 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
7 ms |
5120 KB |
Output is correct |
29 |
Correct |
5 ms |
5180 KB |
Output is correct |
30 |
Correct |
6 ms |
5120 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5248 KB |
Output is correct |
33 |
Correct |
6 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
8 ms |
5248 KB |
Output is correct |
36 |
Correct |
5 ms |
5120 KB |
Output is correct |
37 |
Correct |
5 ms |
5120 KB |
Output is correct |
38 |
Correct |
5 ms |
5248 KB |
Output is correct |
39 |
Correct |
6 ms |
5120 KB |
Output is correct |
40 |
Correct |
6 ms |
5248 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
5 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5248 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
45 |
Correct |
334 ms |
17656 KB |
Output is correct |
46 |
Correct |
326 ms |
17528 KB |
Output is correct |
47 |
Correct |
332 ms |
17768 KB |
Output is correct |
48 |
Correct |
315 ms |
17528 KB |
Output is correct |
49 |
Correct |
326 ms |
17468 KB |
Output is correct |
50 |
Correct |
334 ms |
17604 KB |
Output is correct |
51 |
Correct |
322 ms |
17528 KB |
Output is correct |
52 |
Correct |
331 ms |
17656 KB |
Output is correct |
53 |
Correct |
327 ms |
17440 KB |
Output is correct |
54 |
Correct |
415 ms |
20344 KB |
Output is correct |
55 |
Correct |
408 ms |
19448 KB |
Output is correct |
56 |
Correct |
401 ms |
18808 KB |
Output is correct |
57 |
Correct |
400 ms |
18424 KB |
Output is correct |
58 |
Correct |
304 ms |
16632 KB |
Output is correct |
59 |
Correct |
308 ms |
16504 KB |
Output is correct |
60 |
Correct |
205 ms |
25208 KB |
Output is correct |
61 |
Correct |
261 ms |
22776 KB |
Output is correct |
62 |
Correct |
448 ms |
27132 KB |
Output is correct |
63 |
Correct |
247 ms |
22904 KB |
Output is correct |
64 |
Correct |
254 ms |
22392 KB |
Output is correct |
65 |
Correct |
467 ms |
26872 KB |
Output is correct |
66 |
Correct |
253 ms |
23032 KB |
Output is correct |