제출 #490088

#제출 시각아이디문제언어결과실행 시간메모리
490088fcmalkcinFinancial Report (JOI21_financial)C++17
100 / 100
1864 ms43516 KiB
/*#pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops, no-stack-protector") #pragma GCC target("avx,avx2,fma") */ #include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn=3e5+50; const ll mod=1e9+7 ; const ll base=2e18; /// you will be the best but now you just are trash /// goal 1/7 ll a[maxn]; struct stmx { ll st[4*maxn]; stmx() { memset(st,0,sizeof(st)); } ll get(ll id,ll left,ll right,ll x,ll y) { if (left>y||right<x) return 0; if (x<=left&&right<=y) { return st[id]; } ll mid =(left+right)/2; return max(get(id*2,left,mid,x,y),get(id*2+1,mid+1,right,x,y)); } void update(ll id,ll left,ll right, ll pos,ll diff) { if (pos<left||pos>right) return ; if (left==right) { st[id]=diff; return; } ll mid =(left+right)/2; update(id*2,left,mid,pos,diff); update(id*2+1,mid+1,right,pos,diff); st[id]=max(st[id*2],st[id*2+1]); } }man,man1; set<ll> st; ll n; void add(ll x) { auto it=st.lower_bound(x); if (it!=st.end()) { ll h=(*it); man.update(1,1,n,x,h-x); } if (it!=st.begin()) { it--; ll h=(*it); man.update(1,1,n,h,x-h); } st.insert(x); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll d; cin>> n>> d; vector<pll> vt; for (int i=1;i<=n;i++) { cin>>a[i]; vt.pb(make_pair(a[i],-i)); } sort(vt.begin(),vt.end()); ll ans=0; for (auto p:vt) { ll pos=p.ss; pos=-pos; add(pos); ll l=1,h=pos-1; while (l<=h) { ll mid=(l+h)/2; if (man.get(1,1,n,mid,pos-1)<=d) h=mid-1; else l=mid+1; } ll nw=man1.get(1,1,n,l,pos-1)+1; // cout <<nw<<" "<<l<<" "<<pos<<endl; ans=max(ans,nw); man1.update(1,1,n,pos,nw); } cout <<ans<<endl; }

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

Main.cpp: In function 'int main()':
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...