結果
| 問題 |
No.3284 Picnic with Friends
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-26 23:36:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,183 ms / 7,000 ms |
| コード長 | 2,420 bytes |
| コンパイル時間 | 2,988 ms |
| コンパイル使用メモリ | 229,604 KB |
| 実行使用メモリ | 56,300 KB |
| 最終ジャッジ日時 | 2025-10-08 17:02:04 |
| 合計ジャッジ時間 | 22,439 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#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());
int n = 1000000;
vector<long long> C(n+1),answer(N);
map<long long,long long> M;
for(auto x : X){
int posl = 0,posr = 0;
long long s;
for(s=1; s*s<=x; s++){
long long now = x/s;
C.at(s) += now,C.at(s+1) -= now;
}
while(s <= x){
long long m = x/s,r = x%s;
long long ns = s+r/m+1;
if(s <= n) C.at(s) += m;
else M[s] += m;
if(ns <= n) C.at(ns) -= m;
else M[ns] -= m;
s = ns;
}
}
vector<pair<long long,long long>> V(n);
long long sum = 0;
for(int i=0; i<n; i++){
C.at(i) += sum;
V.at(i) = {C.at(i),i};
sum = C.at(i);
}
for(auto [k,v] : M){
v += sum;
V.push_back({v,k});
sum = v;
}
V.push_back({0,1e18});
int vpos = 0;
for(int i=0; i<N; i++){
auto [a,pos] = A.at(i);
while(true){
auto [ign,a2] = V.at(vpos);
if(a2 <= a) vpos++;
else break;
}
answer.at(pos) = V.at(vpos-1).first;
}
for(auto &a : answer) cout << a << "\n";
}