Submission #865822

# Submission time Handle Problem Language Result Execution time Memory
865822 2023-10-24T18:54:40 Z mychecksedad Measures (CEOI22_measures) C++17
76 / 100
313 ms 36120 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;

int n, m, pos[N], co[N];
ll D, T[N][2], lazy[N][2];
void build(int l, int r, int k){
  lazy[k][0] = lazy[k][1] = 0;
  co[k] = 0;
  if(l == r){
    T[k][0] = -1e18;
    T[k][1] = 1e18;
    co[k] = 0;
    return;
  }
  int mid = l+r>>1;
  build(l, mid, k<<1);
  build(mid+1, r, k<<1|1);
  T[k][0] = -1e18;
  T[k][1] = 1e18;
}
void push(int k){
  for(int r = 0; r < 2; ++r){
    lazy[k<<1][r] += lazy[k][r];
    lazy[k<<1|1][r] += lazy[k][r];
    T[k<<1][r] += lazy[k][r];
    T[k<<1|1][r] += lazy[k][r];
    lazy[k][r] = 0;
  }
}
void sett(int l, int r, int p, int k, ll val){
  if(l == r){
    T[k][0] = val;
    T[k][1] = val;
    co[k] = 1;
    return;
  }
  push(k);
  int mid = l+r>>1;
  if(p <= mid)
    sett(l, mid, p, k<<1, val);
  else
    sett(mid+1, r, p, k<<1|1, val);
  T[k][0] = max(T[k<<1][0], T[k<<1|1][0]);
  T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
  co[k] = co[k<<1] + co[k<<1|1];
}
void update(int l, int r, int ql, int qr, int k, ll add){
  if(ql > r || l > qr) return;
  if(ql <= l && r <= qr){
    T[k][0] += add;
    T[k][1] += add;
    lazy[k][0] += add;
    lazy[k][1] += add;
    return;
  }
  push(k);
  int mid = l+r>>1;
  update(l, mid, ql, qr, k<<1, add);
  update(mid+1, r, ql, qr, k<<1|1, add);
  T[k][0] = max(T[k<<1][0], T[k<<1|1][0]);
  T[k][1] = min(T[k<<1][1], T[k<<1|1][1]);
  co[k] = co[k<<1] + co[k<<1|1];
}
pair<ll, ll> get(int l, int r, int ql, int qr, int k){
  if(ql > r || l > qr) return {(ll)-1e18, (ll)1e18};
  if(ql <= l && r <= qr) return {T[k][0], T[k][1]};
  push(k);
  int mid = l+r>>1;
  auto v1 = get(l, mid, ql, qr, k<<1); 
  auto v2 = get(mid+1, r, ql, qr, k<<1|1); 
  return {max(v1.first, v2.first), min(v1.second, v2.second)};
}
int sum(int l, int r, int ql, int qr, int k){
  if(ql > r || l > qr) return 0;
  if(ql <= l && r <= qr) return co[k];
  push(k);
  int mid = l+r>>1;
  return sum(l, mid, ql, qr, k<<1) + sum(mid+1, r, ql, qr, k<<1|1);
}


void solve(){
  cin >> n >> m >> D;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
  }
  vector<array<ll, 2>> v;
  for(int i = 0; i < m; ++i){
    ll x; cin >> x;
    v.pb({x, i});
  }
  sort(all(v));
  for(int i = 0; i < m; ++i) pos[v[i][1]] = i;
  build(1, m, 1);
  ll ans = 0;
  for(int i = 0; i < m; ++i){
    ll cur = v[pos[i]][0];
    int P = pos[i] + 1;
   
    update(1, m, P + 1, m, 1, D);

    ll val = (sum(1, m, 1, P, 1) + 1) * D - cur;

    ll L = get(1, m, 1, P - 1, 1).second;
    ans = max(ans, val - L);

    ll R = get(1, m, P + 1, m, 1).first;
    ans = max(ans, R - val);

    ans = max(ans, R - L);

    sett(1, m, P, 1, val);
    if(ans % 2 == 0) cout << ans / 2 << ' ';
    else cout << ans/2 << ".5" << ' ';
    // for(auto k: active) cout << k << ' ';
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

Main.cpp: In function 'void build(int, int, int)':
Main.cpp:23:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |   int mid = l+r>>1;
      |             ~^~
Main.cpp: In function 'void sett(int, int, int, int, long long int)':
Main.cpp:46:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int mid = l+r>>1;
      |             ~^~
Main.cpp: In function 'void update(int, int, int, int, int, long long int)':
Main.cpp:65:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |   int mid = l+r>>1;
      |             ~^~
Main.cpp: In function 'std::pair<long long int, long long int> get(int, int, int, int, int)':
Main.cpp:76:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |   int mid = l+r>>1;
      |             ~^~
Main.cpp: In function 'int sum(int, int, int, int, int)':
Main.cpp:85:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   85 |   int mid = l+r>>1;
      |             ~^~
Main.cpp: In function 'int main()':
Main.cpp:130:15: warning: unused variable 'aa' [-Wunused-variable]
  130 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 211 ms 31416 KB Output is correct
2 Correct 215 ms 33484 KB Output is correct
3 Correct 219 ms 33840 KB Output is correct
4 Correct 218 ms 32296 KB Output is correct
5 Correct 214 ms 32692 KB Output is correct
6 Correct 210 ms 31676 KB Output is correct
7 Correct 219 ms 32804 KB Output is correct
8 Correct 212 ms 31400 KB Output is correct
9 Correct 211 ms 31132 KB Output is correct
10 Correct 220 ms 33728 KB Output is correct
11 Correct 213 ms 32964 KB Output is correct
12 Correct 231 ms 32980 KB Output is correct
13 Correct 212 ms 31232 KB Output is correct
14 Correct 216 ms 33216 KB Output is correct
15 Correct 228 ms 33120 KB Output is correct
16 Correct 210 ms 31248 KB Output is correct
17 Correct 222 ms 32476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 31416 KB Output is correct
2 Correct 215 ms 33484 KB Output is correct
3 Correct 219 ms 33840 KB Output is correct
4 Correct 218 ms 32296 KB Output is correct
5 Correct 214 ms 32692 KB Output is correct
6 Correct 210 ms 31676 KB Output is correct
7 Correct 219 ms 32804 KB Output is correct
8 Correct 212 ms 31400 KB Output is correct
9 Correct 211 ms 31132 KB Output is correct
10 Correct 220 ms 33728 KB Output is correct
11 Correct 213 ms 32964 KB Output is correct
12 Correct 231 ms 32980 KB Output is correct
13 Correct 212 ms 31232 KB Output is correct
14 Correct 216 ms 33216 KB Output is correct
15 Correct 228 ms 33120 KB Output is correct
16 Correct 210 ms 31248 KB Output is correct
17 Correct 222 ms 32476 KB Output is correct
18 Correct 304 ms 31680 KB Output is correct
19 Correct 298 ms 35732 KB Output is correct
20 Correct 221 ms 36120 KB Output is correct
21 Correct 257 ms 33840 KB Output is correct
22 Correct 266 ms 33664 KB Output is correct
23 Correct 218 ms 33416 KB Output is correct
24 Correct 303 ms 34768 KB Output is correct
25 Correct 210 ms 33216 KB Output is correct
26 Correct 297 ms 33064 KB Output is correct
27 Correct 302 ms 36028 KB Output is correct
28 Correct 265 ms 34452 KB Output is correct
29 Correct 283 ms 35260 KB Output is correct
30 Correct 252 ms 32960 KB Output is correct
31 Correct 254 ms 35008 KB Output is correct
32 Correct 220 ms 35004 KB Output is correct
33 Correct 313 ms 33520 KB Output is correct
34 Correct 258 ms 34492 KB Output is correct