답안 #947981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947981 2024-03-17T11:02:44 Z yeediot 휴가 (IOI14_holiday) C++14
30 / 100
95 ms 6284 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
const long long mxn=1e5+5;
multiset<long long>bg,sm;
long long n,st,d,L,R;
long long cur,v[mxn];
void sir(long l,long r,long k){
    while(L>l){
        bg.insert(v[--L]);
        cur+=v[L];
        
    }
    while(R<r){
        bg.insert(v[++R]);
        cur+=v[R];
    }
    while(L<l){
        if(bg.find(v[L])!=bg.end()){
            cur-=v[L];
            bg.erase(bg.find(v[L]));
        }
        else{
            sm.erase(sm.find(v[L]));
        }
        L++;
    }
    while(R>r){
        if(bg.find(v[R])!=bg.end()){
            cur-=v[R];
            bg.erase(bg.find(v[R]));
        }
        else{
            sm.erase(sm.find(v[R]));
        }
        R--;
    }
    while(sz(bg)>k){
        cur-=*bg.begin();
        sm.insert(*bg.begin());
        bg.erase(bg.begin());
    }
    while(sz(bg)<k){
        cur+=*prev(sm.end());
        bg.insert(*prev(sm.end()));
        sm.erase(prev(sm.end()));
    }
}
 
long long ans;
void solve(long long l,long long r,long long ql,long long qr){
    if(l>r)return;
    long long mm=(l+r)/2;
    long long mx=0;
    long long best=ql;
    for(long long i=ql;i<=qr;i++){
        long long x=min(i-mm+1,d-(min(i-st,st-mm)+i-mm));
        if(x<=0)continue;
        sir(mm,i,x);
        if(cur>=mx){
            best=i;
            mx=cur;
        }
    }
    chmax(ans,mx);
    solve(l,mm-1,ql,best);
    solve(mm+1,r,best,qr);
}
long long findMaxAttraction(int N,int ST,int D,int a[]){
    n=N,st=ST,d=D,cur=0,L=0,R=n-1;
    for(long long i=0;i<n;i++){
        v[i]=a[i];
        bg.insert(v[i]);
        cur+=v[i];
    }
    solve(0,st,st,n-1);
    return ans;
}
#ifdef local
int main(){
    setio();
    int a,b,c;
    cin>>a>>b>>c;
    int x[n];
    for(int i=0;i<a;i++){
        cin>>x[i];
    }
    cout<<findMaxAttraction(a,b,c,x)<<'\n';
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 /*
 input:
 
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 612 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 6236 KB Output is correct
2 Correct 38 ms 6284 KB Output is correct
3 Correct 37 ms 6236 KB Output is correct
4 Correct 49 ms 6228 KB Output is correct
5 Correct 83 ms 5832 KB Output is correct
6 Correct 15 ms 2372 KB Output is correct
7 Correct 31 ms 3420 KB Output is correct
8 Correct 43 ms 4188 KB Output is correct
9 Correct 10 ms 2136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 8 ms 860 KB Output is correct
5 Correct 6 ms 856 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Incorrect 3 ms 860 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 6208 KB Output is correct
2 Correct 41 ms 6236 KB Output is correct
3 Correct 95 ms 3272 KB Output is correct
4 Incorrect 7 ms 860 KB Output isn't correct
5 Halted 0 ms 0 KB -