답안 #990787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990787 2024-05-31T10:52:19 Z AdamGS 사탕 분배 (IOI21_candies) C++17
100 / 100
260 ms 45396 KB
#include "candies.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=2e5+7;
vector<pair<ll,ll>>V[LIM];
ll trma[4*LIM], trmi[4*LIM], lazy[4*LIM], N=1, n, q;
void spl(int v) {
  trma[2*v]+=lazy[v];
  trma[2*v+1]+=lazy[v];
  trmi[2*v]+=lazy[v];
  trmi[2*v+1]+=lazy[v];
  lazy[2*v]+=lazy[v];
  lazy[2*v+1]+=lazy[v];
  lazy[v]=0;
}
void upd(int v, int l, int r, int a, int b, ll x) {
  if(b<l || r<a) return;
  if(a<=l && r<=b) {
    trma[v]+=x;
    trmi[v]+=x;
    lazy[v]+=x;
    return;
  }
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  upd(2*v, l, mid, a, b, x);
  upd(2*v+1, mid+1, r, a, b, x);
  trma[v]=max(trma[2*v], trma[2*v+1]);
  trmi[v]=min(trmi[2*v], trmi[2*v+1]);
}
ll zejdz(ll c) {
  ll v=1, aktma=-INF, aktmi=INF;
  while(v<N) {
    if(lazy[v]) spl(v);
    if(min(aktmi, trmi[2*v+1])+c>=max(aktma, trma[2*v+1])) {
      aktmi=min(aktmi, trmi[2*v+1]);
      aktma=max(aktma, trma[2*v+1]);
      v=2*v;
    } else v=2*v+1;
  }
  for(int i=1; i<N; i=2*i+1) spl(i);
  aktma=max(aktma, trma[v]);
  aktmi=min(aktmi, trmi[v]);
  if(trma[v]==aktma) {
    return trmi[2*N-1]-aktmi;
  }
  return c-(aktma-trmi[2*N-1]);
}
vector<int>distribute_candies(vector<int>c, vector<int>l, vector<int>r, vector<int>v) {
  n=c.size(); q=l.size();
  while(N<q+3) N*=2;
  upd(1, 0, N-1, 0, 0, -INF);
  upd(1, 0, N-1, 1, 1, INF);
  upd(1, 0, N-1, 2, 2, 0);
  rep(i, q) {
    V[l[i]].pb({v[i], i+3});
    V[r[i]+1].pb({-v[i], i+3});
  }
  vector<int>ans(n);
  rep(i, n) {
    for(auto j : V[i]) upd(1, 0, N-1, j.nd, N-1, j.st);
    ans[i]=zejdz(c[i]);
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 3 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 38068 KB Output is correct
2 Correct 260 ms 38864 KB Output is correct
3 Correct 241 ms 38224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 137 ms 34788 KB Output is correct
3 Correct 48 ms 12868 KB Output is correct
4 Correct 236 ms 38224 KB Output is correct
5 Correct 255 ms 45132 KB Output is correct
6 Correct 248 ms 45396 KB Output is correct
7 Correct 231 ms 44880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 67 ms 32452 KB Output is correct
4 Correct 46 ms 11896 KB Output is correct
5 Correct 126 ms 34732 KB Output is correct
6 Correct 129 ms 38824 KB Output is correct
7 Correct 133 ms 39852 KB Output is correct
8 Correct 132 ms 38056 KB Output is correct
9 Correct 126 ms 40096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 3 ms 9564 KB Output is correct
6 Correct 259 ms 38068 KB Output is correct
7 Correct 260 ms 38864 KB Output is correct
8 Correct 241 ms 38224 KB Output is correct
9 Correct 2 ms 9304 KB Output is correct
10 Correct 137 ms 34788 KB Output is correct
11 Correct 48 ms 12868 KB Output is correct
12 Correct 236 ms 38224 KB Output is correct
13 Correct 255 ms 45132 KB Output is correct
14 Correct 248 ms 45396 KB Output is correct
15 Correct 231 ms 44880 KB Output is correct
16 Correct 2 ms 9308 KB Output is correct
17 Correct 2 ms 9308 KB Output is correct
18 Correct 67 ms 32452 KB Output is correct
19 Correct 46 ms 11896 KB Output is correct
20 Correct 126 ms 34732 KB Output is correct
21 Correct 129 ms 38824 KB Output is correct
22 Correct 133 ms 39852 KB Output is correct
23 Correct 132 ms 38056 KB Output is correct
24 Correct 126 ms 40096 KB Output is correct
25 Correct 2 ms 9308 KB Output is correct
26 Correct 48 ms 13100 KB Output is correct
27 Correct 124 ms 37456 KB Output is correct
28 Correct 259 ms 43344 KB Output is correct
29 Correct 259 ms 43088 KB Output is correct
30 Correct 259 ms 43860 KB Output is correct
31 Correct 240 ms 43352 KB Output is correct
32 Correct 251 ms 44380 KB Output is correct