제출 #503047

#제출 시각아이디문제언어결과실행 시간메모리
503047beksultan04Financial Report (JOI21_financial)C++14
100 / 100
896 ms50764 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; //#define int long long #define pii pair<int,int> #define ret return #define fr first #define sc second #define OK puts("OK"); #define NO puts("NO"); #define YES puts("YES"); #define all(s) s.begin(),s.end() #define allr(s) s.rbegin(),s.rend() #define nosol puts("-1"); #define pb push_back #define endi puts(""); #define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int N = 3e5+12,INF = 1e9+7; int a[N],der[4*N],t[N]; void update(int v,int l,int r,int pos,int x){ if (l == r){ der[v] = x; ret ; } int m = l+r>>1; if (m < pos)update(v<<1|1,m+1,r,pos,x); else update(v<<1,l,m,pos,x); der[v] = max(der[v<<1],der[v<<1|1]); } int get_ans(int v,int l,int r,int ql,int qr){ if (l > qr || r < ql)ret 0; if (ql <= l && r <= qr)ret der[v]; int m = l+r>>1; ret max(get_ans(v<<1,l,m,ql,qr),get_ans(v<<1|1,m+1,r,ql,qr)); } int main(){ int i,n,d,j,ans=0; cin>>n>>d; vector <int> v; set <int> ss{-1}; map <int,int> mp; for (i=1;i<=n;++i){ cin>>a[i]; ss.insert(a[i]); } int cnt = 0; for (auto x:ss) mp[x] = cnt++; for (i=1;i<=n;++i){ a[i] = mp[a[i]]; } multiset <int> s; set <int> t; for (i=1;i<=n;++i){ int mx = get_ans(1,0,cnt,0,a[i]-1); if (get_ans(1,0,cnt,a[i],a[i]) < mx+1) update(1,0,cnt,a[i],mx+1); s.insert(a[i]); ans = max(ans,mx+1); if (i > d){ s.erase(s.lower_bound(a[i-d])); if (*s.begin() > a[i-d]){ update(1,0,cnt,a[i-d],0); while (!s.empty() && !t.empty() && *s.begin() > *t.begin()){ update(1,0,cnt,*t.begin(),0); t.erase(t.begin()); } } else t.insert(a[i-d]); } }endi cout <<ans; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void update(int, int, int, int, int)':
Main.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |  int m = l+r>>1;
      |          ~^~
Main.cpp: In function 'int get_ans(int, int, int, int, int)':
Main.cpp:37:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |  int m = l+r>>1;
      |          ~^~
Main.cpp: In function 'int main()':
Main.cpp:43:12: warning: unused variable 'j' [-Wunused-variable]
   43 |  int i,n,d,j,ans=0;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...