제출 #288872

#제출 시각아이디문제언어결과실행 시간메모리
288872mohammedehab2002별자리 3 (JOI20_constellation3)C++11
100 / 100
467 ms27132 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...