結果

問題 No.3284 Picnic with Friends
ユーザー GOTKAKO
提出日時 2025-09-26 22:52:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6,882 ms / 7,000 ms
コード長 2,064 bytes
コンパイル時間 2,677 ms
コンパイル使用メモリ 223,020 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2025-09-26 22:53:49
合計ジャッジ時間 77,157 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long solve(vector<long long> H){
    map<vector<long long>,int> M;
    queue<vector<long long>> Q;
    M[H] = 0,Q.push(H);
    int N = H.size();
    long long inf = 2e18;
    while(Q.size()){
        auto A = Q.front(); Q.pop();
        auto nowd = M[A];
        long long at = inf;
        if(nowd <= 60) at = 1LL<<nowd;
        for(int i=0; i<N; i++) if(A.at(i) > 0){
            long long memo = A.at(i);
            A.at(i) = max(0LL,A.at(i)-at);
            if(M.count(A) == false){
                M[A] = nowd+1,Q.push(A);
            }
            A.at(i) = memo;
        }
    }

    for(auto &h : H) h = 0;
    return M[H];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N; cin >> N;
    vector<pair<long long,int>> A(N);
    int idx = 0;
    for(auto &[a,p] : A) cin >> a,p = idx++;
    sort(A.begin(),A.end());

    int Q; cin >> Q;
    vector<long long> X;
    long long start = -1,time = -1;
    while(Q--){
        long long t,f; cin >> t >> f;
        if(time < t){
            if(start != -1) X.push_back(time-start);
            start = t,time = t+f;
        }
        else time += f;
    }
    X.push_back(time-start);
    sort(X.begin(),X.end());
    auto f = [&](long long s) -> int {
        int pos = lower_bound(A.begin(),A.end(),pair{s,-1})-A.begin();
        return pos;
    };
    vector<long long> C(N+1),answer(N);
    for(auto x : X){
        long long s;
        for(s=1; s*s<=x; s++){
            int posl = f(s),posr = f(s+1);
            long long now = x/s;
            C.at(posl) += now,C.at(posr) -= now;
        }
        while(s <= x){
            long long m = x/s,r = x%s;
            long long ns = s+r/m+1;
            int posl = f(s),posr = f(ns);
            C.at(posl) += m,C.at(posr) -= m;
            s = ns;
        }
    } 

    for(int i=1; i<N; i++) C.at(i) += C.at(i-1);
    for(int i=0; i<N; i++){
        auto [ign,pos] = A.at(i);
        answer.at(pos) = C.at(i);
    }
    for(auto &a : answer) cout << a << "\n";
}
0