提出 #58225048
ソースコード 拡げる
//yukicoder@cpp17
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <random>
#include <bitset>
#include <complex>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
*/
template< typename T, typename F>
struct SegmentTree{
private:
int n;
vector<T> node;
F f;
T initer;
public:
SegmentTree(int n_, F f, T initer) : f(f),initer(initer) {
n = 1;
while(n < n_)n*=2;
node.resize(2*n-1, initer);
}
SegmentTree(int n_, F f,T initer, vector<T> x) : f(f),initer(initer) {
n = 1;
while(n < n_)n*=2;
node.resize(2*n-1, initer);
set(x);
}
void set(vector<T> x){
for(int i = 0; (int)x.size() > i; i++){
update(i,x[i]);
}
}
void update(int x, T val){
x += (n-1);
node[x] = val;
while(x > 0){
x = (x-1)/2;
node[x] = f(node[2*x+1],node[2*x+2]);
}
}
void add(int x, T val){
x += (n-1);
node[x] += val;
while(x > 0){
x = (x-1)/2;
node[x] = f(node[2*x+1],node[2*x+2]);
}
}
T getf(int a,int b, int k=0, int l=0, int r=-1){
if(r < 0){
r = n-1;
}
if(r < a || b < l){
return initer;
}
if(a <= l && r <= b){
return node[k];
}
T vl = getf(a,b,2*k+1,l,(l+r)/2);
T vr = getf(a,b,2*k+2,(l+r)/2+1,r);
return f(vl,vr);
}
void debug(){
int nw = 1;
int curr = 1;
cout << "---begin---" << endl;
for(int i = 0; 2*n-1 > i; i++){
cout << node[i] << " ";
if(nw == curr)cout << endl,nw *= 2, curr=1;
else curr++;
}
cout << "---end---" << endl;
}
};
template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer){
return SegmentTree<T,F>{N,f,initer};
}
template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer, vector<T> x){
return SegmentTree<T,F>{N,f,initer,x};
}
int main(){
long long n,m,k;cin>>n>>m>>k;
if(n == m){
for(int i = 0; n > i; i++){
cout << "0" << " \n"[i+1==n];
}
return 0;
}
vector<pair<long long,int>> A(n);
for(int i = 0; n > i; i++){
cin>>A[i].first;k-=A[i].first;
A[i].second = i;
}
sort(A.begin(), A.end(), greater<pair<long long, int>>());
vector<long long> B(n);
for(int i = 0; n > i; i++){
B[i] = A[i].first;
}
auto seg = get_segment_tree(n, [](pair<long long, int> a, pair<long long, int> b){return make_pair(a.first+b.first, -1);}, {0,0}, A);
vector<long long> ans(n);
for(int i = 0; n > i; i++){
long long mn = -1;
long long mx = k+2;
while(mx-mn>1){
long long ce = (mn+mx)/2;
long long mys = A[i].first+ce;
int lt = lower_bound(B.begin(), B.end(), mys, greater<long long>())-B.begin();
int rt = m + (m > i ? 0 : -1);
if(lt > rt){
mn = ce;
continue;
}
int c = rt-lt+1;
auto other = seg.getf(lt, rt).first + (k-ce);
if(lt <= i && i <= rt){
other -= A[i].first;
c--;
}
if(c == 0){
assert(false);
return 0;
}
//cout << lt << " " << rt << " " << other << " " << c << " " << mys << " " << A[i].first << endl;
if(other/c <= mys){
mx = ce;
}else{
mn = ce;
}
}
//cout << mn << " " << mx << endl;
if(mx > k){
ans[A[i].second] = -1;
}else{
ans[A[i].second] = mx;
}
}
for(int i = 0; n > i; i++){
cout << ans[i] << " \n"[i+1==n];
}
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt, 02_hand_07.txt, 02_hand_08.txt, 02_hand_09.txt, 02_hand_10.txt, 02_hand_11.txt, 03_large_k_00.txt, 03_large_k_01.txt, 03_large_k_02.txt, 03_large_k_03.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3504 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3552 KiB |
| 01_random_00.txt |
AC |
293 ms |
13392 KiB |
| 01_random_01.txt |
AC |
469 ms |
14968 KiB |
| 01_random_02.txt |
AC |
578 ms |
24728 KiB |
| 01_random_03.txt |
AC |
536 ms |
22344 KiB |
| 01_random_04.txt |
AC |
532 ms |
15452 KiB |
| 01_random_05.txt |
AC |
651 ms |
25216 KiB |
| 01_random_06.txt |
AC |
1 ms |
3552 KiB |
| 01_random_07.txt |
AC |
1 ms |
3488 KiB |
| 01_random_08.txt |
AC |
1 ms |
3556 KiB |
| 01_random_09.txt |
AC |
1 ms |
3580 KiB |
| 01_random_10.txt |
AC |
3 ms |
3684 KiB |
| 01_random_11.txt |
AC |
2 ms |
3556 KiB |
| 01_random_12.txt |
AC |
854 ms |
25320 KiB |
| 01_random_13.txt |
AC |
648 ms |
25332 KiB |
| 01_random_14.txt |
AC |
664 ms |
25268 KiB |
| 01_random_15.txt |
AC |
640 ms |
25268 KiB |
| 01_random_16.txt |
AC |
604 ms |
25212 KiB |
| 01_random_17.txt |
AC |
648 ms |
25344 KiB |
| 01_random_18.txt |
AC |
1065 ms |
25352 KiB |
| 01_random_19.txt |
AC |
646 ms |
25280 KiB |
| 01_random_20.txt |
AC |
395 ms |
25260 KiB |
| 01_random_21.txt |
AC |
390 ms |
25352 KiB |
| 01_random_22.txt |
AC |
142 ms |
25264 KiB |
| 01_random_23.txt |
AC |
178 ms |
25332 KiB |
| 01_random_24.txt |
AC |
402 ms |
25332 KiB |
| 02_hand_00.txt |
AC |
669 ms |
25344 KiB |
| 02_hand_01.txt |
AC |
618 ms |
25252 KiB |
| 02_hand_02.txt |
AC |
656 ms |
25356 KiB |
| 02_hand_03.txt |
AC |
677 ms |
25344 KiB |
| 02_hand_04.txt |
AC |
698 ms |
25392 KiB |
| 02_hand_05.txt |
AC |
650 ms |
25348 KiB |
| 02_hand_06.txt |
AC |
648 ms |
25260 KiB |
| 02_hand_07.txt |
AC |
721 ms |
25488 KiB |
| 02_hand_08.txt |
AC |
69 ms |
25264 KiB |
| 02_hand_09.txt |
AC |
233 ms |
25268 KiB |
| 02_hand_10.txt |
AC |
76 ms |
25296 KiB |
| 02_hand_11.txt |
AC |
7 ms |
3540 KiB |
| 03_large_k_00.txt |
AC |
59 ms |
6276 KiB |
| 03_large_k_01.txt |
AC |
23 ms |
5996 KiB |
| 03_large_k_02.txt |
AC |
158 ms |
22164 KiB |
| 03_large_k_03.txt |
AC |
12 ms |
4492 KiB |