Submission #391314

# Submission time Handle Problem Language Result Execution time Memory
391314 2021-04-18T14:06:54 Z usachevd0 Horses (IOI15_horses) C++14
100 / 100
211 ms 54548 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
  return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
  return y > x ? (x = y, true) : false;
}
void debug_out() {
  cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
  cerr << ' ' << A;
  debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
  for (int i = 0; i < n; ++i) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
#ifdef DEBUG
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
  #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
  #define debug(...) 1337
  #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
  for (auto& x : v) {
    stream << x << ' ';
  }
  return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
  return stream << p.first << ' ' << p.second;
}


const int MOD = 1e9 + 7;

struct Num {
  int a;
  bool big;

  Num(): a(0), big(0) {}
  Num(ll _a) {
    assert(_a >= 0);
    a = _a % MOD;
    big = _a >= MOD;
  }
  Num(const Num& oth): a(oth.a), big(oth.big) {}

  Num& operator += (const Num& oth) {
    big |= oth.big;
    if ((a += oth.a) >= MOD) {
      big = true;
      a -= MOD;
    }
    return *this;
  }
  Num& operator *= (const Num& oth) {
    ll prod = a * (ll)oth.a;
    big |= oth.big || prod >= MOD;
    a = prod % MOD;
    return *this;
  }
};
Num operator + (const Num& lhs, const Num& rhs) {
  return Num(lhs) += rhs;
}
Num operator * (const Num& lhs, const Num& rhs) {
  return Num(lhs) *= rhs;
}

struct Node {
  Num f;
  Num p;
  ld ratio;

  Node() {
    f = Num();
    p = 1;
    ratio = 0;
  }
  Node(int x, int y) {
    f = Num(x * (ll)y);
    p = x;
    ratio = y;
  }
};
Node operator * (const Node& lhs, const Node& rhs) {
  Node res;
  res.p = lhs.p * rhs.p;
  if (rhs.f.big || rhs.f.a > lhs.ratio) {
    res.f = rhs.f * lhs.p;
    res.ratio = rhs.ratio;
  } else {
    res.f = lhs.f;
    res.ratio = lhs.ratio / (ld)rhs.p.a;
  }
  return res;
}

const int logN = 19;
const int N = 1 << logN;
int n;
Node t[2 * N];
int X[N], Y[N];

void build() {
  for (int i = 0; i < n; ++i) {
    t[i + N] = Node(X[i], Y[i]);
  }
  for (int v = N - 1; v >= 1; --v) {
    t[v] = t[v << 1] * t[v << 1 | 1];
  }
}

void mdf(int i, int x, int y) {
  X[i] = x;
  Y[i] = y;
  int v = i + N;
  t[v] = Node(x, y);
  for (v >>= 1; v >= 1; v >>= 1) {
    t[v] = t[v << 1] * t[v << 1 | 1];
  }
}

int gt() {
  return t[1].f.a;
}

int init(int _n, int* x, int* y) {
  n = _n;
  memcpy(X, x, n << 2);
  memcpy(Y, y, n << 2);
  build();
  return gt();
}

int updateX(int i, int x) {
  mdf(i, x, Y[i]);
  return gt();
}

int updateY(int i, int y) {
  mdf(i, X[i], y);
  return gt();
}


#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
  freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  int* x = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  int* y = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> y[i];
  }
  cout << init(n, x, y) << '\n';
  int Q;
  cin >> Q;
  while (Q--) {
    int tp, pos, val;
    cin >> tp >> pos >> val;
    if (tp == 1) {
      cout << updateX(pos, val) << '\n';
    } else {
      cout << updateY(pos, val) << '\n';
    }
  }

  return 0;
}
#endif

Compilation message

horses.cpp: In constructor 'Num::Num(ll)':
horses.cpp:63:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   63 |     a = _a % MOD;
      |         ~~~^~~~~
horses.cpp: In member function 'Num& Num::operator*=(const Num&)':
horses.cpp:79:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |     a = prod % MOD;
      |         ~~~~~^~~~~
horses.cpp: In constructor 'Node::Node()':
horses.cpp:96:13: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
   96 |     f = Num();
      |             ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp:97:9: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
   97 |     p = 1;
      |         ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp: In constructor 'Node::Node(int, int)':
horses.cpp:101:22: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
  101 |     f = Num(x * (ll)y);
      |                      ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp:102:9: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
  102 |     p = x;
      |         ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp: In function 'Node operator*(const Node&, const Node&)':
horses.cpp:108:23: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
  108 |   res.p = lhs.p * rhs.p;
      |                       ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp:110:25: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
  110 |     res.f = rhs.f * lhs.p;
      |                         ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
horses.cpp:113:17: warning: implicitly-declared 'constexpr Num& Num::operator=(const Num&)' is deprecated [-Wdeprecated-copy]
  113 |     res.f = lhs.f;
      |                 ^
horses.cpp:66:3: note: because 'Num' has user-provided 'Num::Num(const Num&)'
   66 |   Num(const Num& oth): a(oth.a), big(oth.big) {}
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 33100 KB Output is correct
2 Correct 30 ms 33136 KB Output is correct
3 Correct 30 ms 33124 KB Output is correct
4 Correct 30 ms 33120 KB Output is correct
5 Correct 31 ms 33116 KB Output is correct
6 Correct 30 ms 33100 KB Output is correct
7 Correct 30 ms 33092 KB Output is correct
8 Correct 30 ms 33080 KB Output is correct
9 Correct 31 ms 33136 KB Output is correct
10 Correct 30 ms 33124 KB Output is correct
11 Correct 29 ms 33272 KB Output is correct
12 Correct 33 ms 33100 KB Output is correct
13 Correct 32 ms 33124 KB Output is correct
14 Correct 32 ms 33096 KB Output is correct
15 Correct 32 ms 33084 KB Output is correct
16 Correct 30 ms 33100 KB Output is correct
17 Correct 30 ms 33140 KB Output is correct
18 Correct 30 ms 33028 KB Output is correct
19 Correct 30 ms 33136 KB Output is correct
20 Correct 30 ms 33032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 33100 KB Output is correct
2 Correct 30 ms 33132 KB Output is correct
3 Correct 30 ms 33136 KB Output is correct
4 Correct 30 ms 33132 KB Output is correct
5 Correct 30 ms 33064 KB Output is correct
6 Correct 32 ms 33132 KB Output is correct
7 Correct 32 ms 33100 KB Output is correct
8 Correct 30 ms 33144 KB Output is correct
9 Correct 30 ms 33140 KB Output is correct
10 Correct 29 ms 33092 KB Output is correct
11 Correct 30 ms 33100 KB Output is correct
12 Correct 31 ms 33140 KB Output is correct
13 Correct 30 ms 33100 KB Output is correct
14 Correct 30 ms 33100 KB Output is correct
15 Correct 29 ms 33140 KB Output is correct
16 Correct 30 ms 33172 KB Output is correct
17 Correct 30 ms 33120 KB Output is correct
18 Correct 30 ms 33100 KB Output is correct
19 Correct 30 ms 33100 KB Output is correct
20 Correct 30 ms 33104 KB Output is correct
21 Correct 30 ms 33064 KB Output is correct
22 Correct 30 ms 33136 KB Output is correct
23 Correct 31 ms 33148 KB Output is correct
24 Correct 32 ms 33164 KB Output is correct
25 Correct 31 ms 33176 KB Output is correct
26 Correct 31 ms 33220 KB Output is correct
27 Correct 35 ms 33132 KB Output is correct
28 Correct 31 ms 33144 KB Output is correct
29 Correct 31 ms 33100 KB Output is correct
30 Correct 31 ms 33096 KB Output is correct
31 Correct 30 ms 33080 KB Output is correct
32 Correct 31 ms 33140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 45764 KB Output is correct
2 Correct 211 ms 54548 KB Output is correct
3 Correct 175 ms 45688 KB Output is correct
4 Correct 179 ms 49524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 33068 KB Output is correct
2 Correct 30 ms 33100 KB Output is correct
3 Correct 30 ms 33100 KB Output is correct
4 Correct 30 ms 33128 KB Output is correct
5 Correct 30 ms 33148 KB Output is correct
6 Correct 35 ms 33100 KB Output is correct
7 Correct 35 ms 33044 KB Output is correct
8 Correct 30 ms 33100 KB Output is correct
9 Correct 30 ms 33072 KB Output is correct
10 Correct 30 ms 33116 KB Output is correct
11 Correct 30 ms 33152 KB Output is correct
12 Correct 30 ms 33056 KB Output is correct
13 Correct 31 ms 33100 KB Output is correct
14 Correct 30 ms 33084 KB Output is correct
15 Correct 30 ms 33056 KB Output is correct
16 Correct 30 ms 33072 KB Output is correct
17 Correct 31 ms 33140 KB Output is correct
18 Correct 30 ms 33008 KB Output is correct
19 Correct 30 ms 33208 KB Output is correct
20 Correct 30 ms 33140 KB Output is correct
21 Correct 30 ms 33088 KB Output is correct
22 Correct 30 ms 33100 KB Output is correct
23 Correct 31 ms 33100 KB Output is correct
24 Correct 31 ms 33140 KB Output is correct
25 Correct 31 ms 33188 KB Output is correct
26 Correct 33 ms 33184 KB Output is correct
27 Correct 35 ms 33100 KB Output is correct
28 Correct 36 ms 33244 KB Output is correct
29 Correct 31 ms 33148 KB Output is correct
30 Correct 32 ms 33172 KB Output is correct
31 Correct 30 ms 33164 KB Output is correct
32 Correct 32 ms 33164 KB Output is correct
33 Correct 69 ms 44876 KB Output is correct
34 Correct 70 ms 44944 KB Output is correct
35 Correct 87 ms 51780 KB Output is correct
36 Correct 89 ms 51956 KB Output is correct
37 Correct 57 ms 43084 KB Output is correct
38 Correct 57 ms 43964 KB Output is correct
39 Correct 51 ms 43004 KB Output is correct
40 Correct 68 ms 46916 KB Output is correct
41 Correct 59 ms 43076 KB Output is correct
42 Correct 50 ms 43204 KB Output is correct
43 Correct 63 ms 47220 KB Output is correct
44 Correct 65 ms 47220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 33100 KB Output is correct
2 Correct 30 ms 33100 KB Output is correct
3 Correct 30 ms 33100 KB Output is correct
4 Correct 30 ms 33136 KB Output is correct
5 Correct 34 ms 33100 KB Output is correct
6 Correct 31 ms 33104 KB Output is correct
7 Correct 30 ms 33100 KB Output is correct
8 Correct 30 ms 33084 KB Output is correct
9 Correct 31 ms 33140 KB Output is correct
10 Correct 30 ms 33036 KB Output is correct
11 Correct 29 ms 33124 KB Output is correct
12 Correct 30 ms 33252 KB Output is correct
13 Correct 31 ms 33144 KB Output is correct
14 Correct 30 ms 33080 KB Output is correct
15 Correct 30 ms 33032 KB Output is correct
16 Correct 30 ms 33096 KB Output is correct
17 Correct 34 ms 33088 KB Output is correct
18 Correct 30 ms 33140 KB Output is correct
19 Correct 31 ms 33092 KB Output is correct
20 Correct 33 ms 33064 KB Output is correct
21 Correct 33 ms 33148 KB Output is correct
22 Correct 30 ms 33100 KB Output is correct
23 Correct 31 ms 33228 KB Output is correct
24 Correct 31 ms 33144 KB Output is correct
25 Correct 31 ms 33272 KB Output is correct
26 Correct 32 ms 33156 KB Output is correct
27 Correct 32 ms 33228 KB Output is correct
28 Correct 30 ms 33140 KB Output is correct
29 Correct 31 ms 33168 KB Output is correct
30 Correct 31 ms 33100 KB Output is correct
31 Correct 37 ms 33128 KB Output is correct
32 Correct 31 ms 33100 KB Output is correct
33 Correct 105 ms 45684 KB Output is correct
34 Correct 200 ms 54456 KB Output is correct
35 Correct 163 ms 45632 KB Output is correct
36 Correct 189 ms 49644 KB Output is correct
37 Correct 78 ms 44868 KB Output is correct
38 Correct 69 ms 44896 KB Output is correct
39 Correct 88 ms 51800 KB Output is correct
40 Correct 92 ms 51764 KB Output is correct
41 Correct 59 ms 43140 KB Output is correct
42 Correct 57 ms 44228 KB Output is correct
43 Correct 53 ms 42924 KB Output is correct
44 Correct 68 ms 46896 KB Output is correct
45 Correct 54 ms 43052 KB Output is correct
46 Correct 52 ms 43036 KB Output is correct
47 Correct 66 ms 47264 KB Output is correct
48 Correct 69 ms 47312 KB Output is correct
49 Correct 177 ms 46960 KB Output is correct
50 Correct 191 ms 46896 KB Output is correct
51 Correct 146 ms 53712 KB Output is correct
52 Correct 141 ms 53264 KB Output is correct
53 Correct 167 ms 45304 KB Output is correct
54 Correct 114 ms 45816 KB Output is correct
55 Correct 104 ms 44092 KB Output is correct
56 Correct 127 ms 48700 KB Output is correct
57 Correct 106 ms 44656 KB Output is correct
58 Correct 107 ms 45124 KB Output is correct
59 Correct 69 ms 47336 KB Output is correct