Submission #929208

# Submission time Handle Problem Language Result Execution time Memory
929208 2024-02-17T23:13:30 Z OAleksa Horses (IOI15_horses) C++14
17 / 100
282 ms 69712 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 69;
const int N = 5e5 + 69;
long long n, a[N], b[N], c[N], p[4 * N], g[4 * N];
set<int> st;
long long mul(long long x, long long y) {
   long long r = 1ll * x * y;
   if (r >= mod)
      r %= mod;
   return r;
}
void modify(int v, int tl, int tr, int pos, int x) {
   if (tl == tr)
      p[v] = g[v] = x;
   else {
      int mid = (tl + tr) / 2;
      if (pos <= mid)
         modify(v * 2, tl, mid, pos, x);
      else
         modify(v * 2 + 1, mid + 1, tr, pos, x);
      if (p[v * 2] == -1 || p[v * 2 + 1] == -1 || p[v * 2] > inf / p[v * 2 + 1])
         p[v] = -1;
      else
         p[v] = p[v * 2] * p[v * 2 + 1];
      g[v] = mul(g[v * 2], g[v * 2 + 1]);
   }
}
long long get(int v, int tl, int tr, int l, int r) {
   if (tl > r || tr < l)
      return 1;
   else if (tl >= l && tr <= r)
      return p[v];
   else {
      int mid = (tl + tr) / 2;
      auto l1 = get(v * 2, tl, mid, l, r);
      auto r1 = get(v * 2 + 1, mid + 1, tr, l, r);
      if (l1 == -1 || r1 == -1 || l1 > inf / r1)
         return -1;
      return l1 * r1;
   }
}
long long Get(int v, int tl, int tr, int l, int r) {
   if (tl > r || tr < l)
      return 1;
   else if (tl >= l && tr <= r)
      return g[v];
   else {
      int mid = (tl + tr) / 2;
      return mul(Get(v * 2, tl, mid, l, r), Get(v * 2 + 1, mid + 1, tr, l, r));
   }
}
int Better(int i, int j) {
   if (i > j)
      swap(i, j);
   long long x = get(1, 1, n, i + 1, j);
   if (x < 0)
      return j;
   return (b[i] / b[j] > x ? i : j);
}
long long Result(int i) {
   return mul(Get(1, 1, n, 1, i), b[i]);
}
int Solve() {
   int bst = 1, x = a[1];
   st.insert(1);
   for (int i = 2;i <= n;i++) {
      if (x > inf / a[i]) {
         x = 1;
         bst = i;
         st.insert(i);
      }
      else {
         x *= a[i];
         if (b[i] > b[bst] / x) {
            x = 1;
            bst = i;
            st.insert(i);
         }
      }
   }
   return Result(bst);
}

int init(int N, int X[], int Y[]) {
   n = N;
   fill(p, p + 4 * n + 10, 1);
   fill(g, g + 4 * n + 10, 1);
   for (int i = 1;i <= n;i++) {
      a[i] = X[i - 1], b[i] = Y[i - 1];
      modify(1, 1, n, i, a[i]);
   }
   return Solve();
}

int updateX(int pos, int val) {
   pos++;
   a[pos] = val;
   modify(1, 1, n, pos, a[pos]);
   auto u = st.lower_bound(pos);
   if (u != st.begin()) {
      if (Better(*--u, pos) == pos)
         st.insert(pos);
      else if (st.count(pos))
         st.erase(pos);
   }
   u = st.upper_bound(pos);
   while (u != st.end() && Better(*u, pos) == pos) {
      st.erase(u);
      u = st.upper_bound(pos);
   }
   assert(!st.empty());
	return Result(*st.rbegin());
}

int updateY(int pos, int val) {
   pos++;
	b[pos] = val;
	auto u = st.lower_bound(pos);
   if (u != st.begin()) {
      if (Better(*--u, pos) == pos)
         st.insert(pos);
      else if (st.count(pos))
         st.erase(pos);
   }
   u = st.upper_bound(pos);
   while (u != st.end() && Better(*u, pos) == pos) {
      st.erase(u);
      u = st.upper_bound(pos);
   }
   assert(!st.empty());
	return Result(*st.rbegin());
}
/*
3
2 1 3
3 4 1
1
2 1 2

*/

Compilation message

horses.cpp: In function 'int Better(int, int)':
horses.cpp:58:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   58 |    long long x = get(1, 1, n, i + 1, j);
      |                            ^
horses.cpp: In function 'long long int Result(int)':
horses.cpp:64:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   64 |    return mul(Get(1, 1, n, 1, i), b[i]);
      |                         ^
horses.cpp: In function 'int Solve()':
horses.cpp:67:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   67 |    int bst = 1, x = a[1];
      |                     ~~~^
horses.cpp:76:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |          x *= a[i];
      |          ~~^~~~~~~
horses.cpp:84:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   84 |    return Result(bst);
      |           ~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:87:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   87 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:6:11: note: shadowed declaration is here
    6 | const int N = 5e5 + 69;
      |           ^
horses.cpp:93:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |       modify(1, 1, n, i, a[i]);
      |                    ^
horses.cpp:93:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |       modify(1, 1, n, i, a[i]);
      |                          ~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:101:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |    modify(1, 1, n, pos, a[pos]);
      |                 ^
horses.cpp:101:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |    modify(1, 1, n, pos, a[pos]);
      |                         ~~~~~^
horses.cpp:115:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  115 |  return Result(*st.rbegin());
      |         ~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:134:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  134 |  return Result(*st.rbegin());
      |         ~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6744 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Incorrect 1 ms 6492 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 282 ms 69712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Incorrect 1 ms 6580 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6648 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Incorrect 1 ms 6492 KB Output isn't correct
22 Halted 0 ms 0 KB -