Submission #890777

# Submission time Handle Problem Language Result Execution time Memory
890777 2023-12-22T02:57:03 Z NeroZein Horses (IOI15_horses) C++17
0 / 100
618 ms 75708 KB
#include "horses.h"
#include "bits/stdc++.h"

using namespace std; 

const int N = 5e5 + 5; 
const int md = (int) 1e9 + 7; 

struct node {
  long double mx = 0, sum = 0;
  long long y = 0, mult = 1, lazy = 0, lazymul = 1;
};

int n;
int x[N], y[N];
node seg[N * 2];

int mul(int a, int b) {
  return (int) ((long long) a * b % md); 
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

void push(int nd, int l, int r) {
  if (!seg[nd].lazy) return;
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  seg[nd].mx = seg[nd].mx + log2(seg[nd].lazy) * seg[nd].y;
  if (l == r) {
    seg[nd].sum += log2(seg[nd].lazy); 
    seg[nd].mult = mul(seg[nd].mult, seg[nd].lazymul);
  } else {
    seg[nd + 1].lazy += seg[nd].lazy;
    seg[nd + 1].lazymul = mul(seg[nd].lazymul, seg[nd + 1].lazymul);
    seg[rs].lazy += seg[nd].lazy;
    seg[rs].lazymul = mul(seg[nd].lazymul, seg[rs].lazymul);
  }
  seg[nd].lazy = 0; 
  seg[nd].lazymul = 1; 
}

node merge(node& lx, node& rx) {
  return lx.mx < rx.mx ? rx : lx; 
}

void updX(int nd, int l, int r, int s, int e, int v) {
  push(nd, l, r); 
  if (l >= s && r <= e) {
    seg[nd].lazy = v;
    seg[nd].lazymul = (v < 0 ? inv(-v) : v); 
    push(nd, l, r); 
    return;
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (mid >= s) {
    updX(nd + 1, l, mid, s, e, v);
  } else {
    push(nd + 1, l, mid);
  }
  if (mid < e) {
    updX(rs, mid + 1, r, s, e, v); 
  } else {
    push(rs, mid + 1, r); 
  }
  seg[nd] = merge(seg[nd + 1], seg[rs]); 
}

void updY(int nd, int l, int r, int p, int v) {
  push(nd, l, r);
  if (l == r) {
    seg[nd].y = v;
    seg[nd].mx = seg[nd].sum * seg[nd].y;
    push(nd, l, r); 
    return;
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (p <= mid) {
    push(rs, mid + 1, r); 
    updY(nd + 1, l, mid, p, v);
  } else {
    push(nd + 1, l, mid);
    updY(rs, mid + 1, r, p, v); 
  }
  seg[nd] = merge(seg[nd + 1], seg[rs]); 
}

int get(int nd, int l, int r) {
  if (l == r) {
    return (int) ((long long) seg[nd].mult * y[l] % md);
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  push(nd + 1, l, mid);
  push(rs, mid + 1, r); 
  if (seg[nd + 1].mx < seg[rs].mx) {
    return get(rs, mid + 1, r); 
  } else {
    return get(nd + 1, l, mid); 
  }
}

int init(int N_, int X[], int Y[]) {
  n = N_;
  for (int i = 0; i < n; ++i) {
    y[i] = Y[i];
    updY(0, 0, n - 1, i, y[i]); 
  }
  for (int i = 0; i < n; ++i) {
    x[i] = X[i];
    updX(0, 0, n - 1, i, n - 1, x[i]); 
  }
  return get(0, 0, n - 1); 
}

int updateX(int pos, int val) { 
  updX(0, 0, n - 1, pos, n - 1, -x[pos]);
  x[pos] = val;
  updX(0, 0, n - 1, pos, n - 1, x[pos]); 
  return get(0, 0, n - 1);
}

int updateY(int pos, int val) {
  y[pos] = val;
  updY(0, 0, n - 1, pos, y[pos]); 
  return get(0, 0, n - 1);
}

Compilation message

horses.cpp: In function 'void push(int, int, int)':
horses.cpp:40:58: warning: conversion from 'long long int' to '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} may change value [-Wconversion]
   40 |   seg[nd].mx = seg[nd].mx + log2(seg[nd].lazy) * seg[nd].y;
      |                                                  ~~~~~~~~^
horses.cpp:43:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   43 |     seg[nd].mult = mul(seg[nd].mult, seg[nd].lazymul);
      |                        ~~~~~~~~^~~~
horses.cpp:43:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   43 |     seg[nd].mult = mul(seg[nd].mult, seg[nd].lazymul);
      |                                      ~~~~~~~~^~~~~~~
horses.cpp:46:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   46 |     seg[nd + 1].lazymul = mul(seg[nd].lazymul, seg[nd + 1].lazymul);
      |                               ~~~~~~~~^~~~~~~
horses.cpp:46:60: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   46 |     seg[nd + 1].lazymul = mul(seg[nd].lazymul, seg[nd + 1].lazymul);
      |                                                ~~~~~~~~~~~~^~~~~~~
horses.cpp:48:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |     seg[rs].lazymul = mul(seg[nd].lazymul, seg[rs].lazymul);
      |                           ~~~~~~~~^~~~~~~
horses.cpp:48:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |     seg[rs].lazymul = mul(seg[nd].lazymul, seg[rs].lazymul);
      |                                            ~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 0 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 618 ms 75708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -