이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include"holiday.h"
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=3e5+5;
pair<int,ll> segtree[nax*4];
void build(int pos,int l,int r){
if(l==r){
segtree[pos]={0,0};
return;
}
int mid=(r+l)/2;
build(pos*2+1,l,mid);
build(pos*2+2,mid+1,r);
segtree[pos].fi=segtree[pos*2+1].fi+segtree[pos*2+2].fi;
segtree[pos].se=segtree[pos*2+1].se+segtree[pos*2+2].se;
return;
}
void update(int pos,int l,int r,int idx,int value){
if(l==r){
segtree[pos].fi=value;
segtree[pos].se=(value ? 1 : 0);
return;
}
int mid=(r+l)/2;
if(mid<=idx) update(pos*2+1,l,mid,idx,value);
else update(pos*2+2,mid+1,r,idx,value);
segtree[pos].fi=segtree[pos*2+1].fi+segtree[pos*2+2].fi;
segtree[pos].se=segtree[pos*2+1].se+segtree[pos*2+2].se;
return;
}
long long query(int pos,int l,int r,int cnt){
if(l==r) return (cnt>=segtree[pos].se ? segtree[pos].fi : 0);
int mid=(r+l)/2;
if(cnt>=segtree[pos*2+2].se){
return query(pos*2+1,l,mid,cnt-segtree[pos*2+2].se)+segtree[pos*2+2].fi;
}else{
return query(pos*2+1,l,mid,cnt);
}
}
vector<int> a;
vector<int> b;
pair<ll,int> lefty[nax];
pair<ll,int> righty[nax];
vector<int> cnt(nax);
int m;
void daq(int l,int r,int optl,int optr,int idx){
int mid=(r+l)/2;
for (int i = optl; i <= optr; ++i)
{
update(0,0,m-1,cnt[i],(idx ? b[i] : a[i]));
ll cur=query(0,0,m-1,mid-i);
if((idx ? righty[mid].fi : lefty[mid].fi) < cur){
(idx ? righty[mid] : lefty[mid])={cur,i};
}
}
for (int i = optr; i >= optl; --i)
{
update(0,0,m-1,cnt[i],0);
}
if(l==r) return;
daq(l,mid,optl,(idx ? righty[mid].se : lefty[mid].se),idx);
daq(mid+1,r,(idx ? righty[mid].se : lefty[mid].se),optr,idx);
return;
}
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
vector<pair<int,int>> tab;
for (int i = 0; i < start; ++i)
{
a.pb(attraction[i]);
}
for (int i = start; i < n; ++i)
{
b.pb(attraction[i]);
}
reverse(a.begin(),a.end());
for (int i = 0; i < a.size(); ++i)
{
tab.pb({a[i],i});
}
sort(tab.begin(),tab.end());
for (int i = 0; i < tab.size(); ++i)
{
cnt[tab[i].se]=i;
}
m=a.size();
build(0,0,m-1);
daq(0,d,0,m-1,0);
tab.clear();
for (int i = 0; i < a.size(); ++i)
{
tab.pb({b[i],i});
}
sort(tab.begin(),tab.end());
for (int i = 0; i < tab.size(); ++i)
{
cnt[tab[i].se]=i;
}
m=b.size();
build(0,0,m-1);
daq(0,d,0,m-1,1);
long long ans=0;
for (int i = 0; i <= d; ++i)
{
ans=max(ans,righty[i].fi+( d >= righty[i].se+i+1 ? lefty[d-righty[i].se-i-1].fi : 0));
ans=max(ans,lefty[i].fi+( d>= lefty[i].se+i+1 ? righty[d-lefty[i].se-i-1].fi : 0));
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
holiday.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = 0; i < tab.size(); ++i)
| ~~^~~~~~~~~~~~
holiday.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
holiday.cpp:102:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for (int i = 0; i < tab.size(); ++i)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |