제출 #763469

#제출 시각아이디문제언어결과실행 시간메모리
763469trucmaiFinancial Report (JOI21_financial)C++17
100 / 100
600 ms58320 KiB
//#i_love_aisukiuwu#9998 #include <bits/stdc++.h> using namespace std; void open(){ if(fopen("i.inp","r")){ freopen("i.inp","r",stdin); freopen("o.out","w",stdout); } } #define ll long long #define all(a) (a).begin(), (a).end() #define vi vector<ll> #define pi pair<ll,ll> #define pii pair<ll,pair<ll,ll>> #define fi first #define se second #define gcd __gcd #define mset(a,v) memset(a, v, sizeof(a)) #define endl '\n' #define spc " " const int MN1 = 3e5 + 5,MN2 = 1e4 + 5,LOG = 27; const ll MOD = 1e9 + 7,INF = 1e9; ll n,d,a[MN1],dp[MN1],mx[MN1]; ll st[4*MN1 + 5],lz[4*MN1 + 5]; map<ll,vi>mp; void push(ll i,ll l,ll r){ if(lz[i] == -1) return; st[i] = lz[i]; if(l != r){ lz[2*i] = lz[i]; lz[2*i+1] = lz[i]; } lz[i] = -1; } void upd(ll i,ll l,ll r,ll ql,ll qr,ll val){ push(i,l,r); if(l > qr || r < ql) return; if(ql <= l && r <= qr){ lz[i] = val; push(i,l,r); return; } ll m = (r+l) >> 1; upd(2*i,l,m,ql,qr,val); upd(2*i+1,m+1,r,ql,qr,val); st[i] = max(st[2*i],st[2*i+1]); } ll get(ll i,ll l,ll r,ll ql,ll qr){ push(i,l,r); if(l > qr || r < ql) return 0; if(ql <= l && r <= qr) return st[i]; ll m = (r+l) >> 1; ll left = get(2*i,l,m,ql,qr), right = get(2*i+1,m+1,r,ql,qr); return max(left,right); } void upd(ll ql,ll qr,ll val){upd(1,1,n,ql,qr,val); } ll get(ll ql,ll qr){return get(1,1,n,ql,qr);} void compress(){ ll cnt = 0; for(auto node : mp){ ++cnt; for(ll i : node.se) a[i] = cnt; } } void solve(){ cin>>n>>d; mset(lz,-1); for(ll i = 1;i <= n;++i){ cin>>a[i]; mp[a[i]].push_back(i); } compress(); deque<ll>dq; for(ll i = 1;i <= n;++i){ while(!dq.empty() && a[dq.back()] >= a[i]) dq.pop_back(); while(!dq.empty() && dq.front() + d <= i) dq.pop_front(); dq.push_back(i); if(i >= d) mx[i] = a[dq.front()]; } for(ll i = 1;i <= n;++i){ dp[i] = 1; dp[i] = max(dp[i],get(1,a[i]-1) + 1); // cout<<"GET: "<<get(1,a[i]-1)<<endl; upd(a[i],a[i],max(dp[i],get(a[i],a[i]))); dp[i] = max(dp[i],get(a[i],n)); if(i >= d) upd(1,mx[i]-1,0); // cout<<dp[i]<<endl; } cout<<dp[n]; } signed main(){ cin.tie(0) -> sync_with_stdio(0); open(); ll t = 1; //cin>>t; while(t--) solve(); cerr << "\n" << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; }

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

Main.cpp: In function 'void open()':
Main.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("i.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("o.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...