Submission #308463

# Submission time Handle Problem Language Result Execution time Memory
308463 2020-10-01T09:11:24 Z quocnguyen1012 Horses (IOI15_horses) C++14
100 / 100
231 ms 58832 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 5e5 + 5, mod = 1e9 + 7;

struct Node {
  ll a, b;
  double la, lb;
};

Node operator + (const Node & l, const Node & r) {
  Node res;
  res.a = l.a * r.a % mod;
  res.la = l.la + r.la;
  if (l.lb > l.la + r.lb) {
    res.lb = l.lb;
    res.b = l.b;
  } else {
    res.lb = l.la + r.lb;
    res.b = l.a * r.b % mod;
  }
  return res;
}

Node tr[4 * maxn];
vector<ll> x, y;
int N;

void apply(int id, int l) {
  tr[id].a = x[l];
  tr[id].b = x[l] * y[l] % mod;
  tr[id].la = log2(x[l]);
  tr[id].lb = log2(y[l]) + log2(x[l]);
}

#define lc id << 1
#define rc id << 1 | 1
void build(int id, int l, int r) {
  if (l == r) {
    apply(id, l);
    return;
  }
  int mid = (l + r) / 2;
  build(lc, l, mid); build(rc, mid + 1, r);
  tr[id] = tr[lc] + tr[rc];
}

void upd(int type, int pos, ll v, int id = 1, int l = 0, int r = N - 1) {
  if (l == r) {
    if (type == 0) x[l] = v;
    else y[l] = v;
    apply(id, pos);
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid) upd(type, pos, v, lc, l, mid);
  else upd(type, pos, v, rc, mid + 1, r);
  tr[id] = tr[lc] + tr[rc];
}

#undef lc
#undef rc
int init(int _N, int X[], int Y[]) {
	N = _N;
  for (int i = 0; i < N; ++i) {
    x.eb(X[i]);
    y.eb(Y[i]);
  }
  build(1, 0, N - 1);
	return tr[1].b;
}

int updateX(int pos, int val) {
	upd(0, pos, val);
	return tr[1].b;
}

int updateY(int pos, int val) {
	upd(1, pos, val);
	return tr[1].b;
}

#ifdef LOCAL
signed main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL

  int N;
  cin >> N;
  int X[N], Y[N];
  for(int i = 0; i < N; i++) cin >> X[i];
  for(int i = 0; i < N; i++) cin >> Y[i];
  cout << init(N, X, Y) << ' ';

  cout << updateY(1, 2);
}
#endif // LOCAL

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:81:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   81 |  return tr[1].b;
      |         ~~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:86:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   86 |  return tr[1].b;
      |         ~~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:91:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   91 |  return tr[1].b;
      |         ~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 46160 KB Output is correct
2 Correct 231 ms 58832 KB Output is correct
3 Correct 168 ms 49964 KB Output is correct
4 Correct 192 ms 53712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 93 ms 49104 KB Output is correct
34 Correct 95 ms 49104 KB Output is correct
35 Correct 130 ms 56136 KB Output is correct
36 Correct 129 ms 56016 KB Output is correct
37 Correct 69 ms 47316 KB Output is correct
38 Correct 92 ms 48368 KB Output is correct
39 Correct 62 ms 47184 KB Output is correct
40 Correct 105 ms 51272 KB Output is correct
41 Correct 62 ms 47312 KB Output is correct
42 Correct 62 ms 47312 KB Output is correct
43 Correct 101 ms 51536 KB Output is correct
44 Correct 104 ms 51536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 114 ms 50000 KB Output is correct
34 Correct 227 ms 58732 KB Output is correct
35 Correct 163 ms 49876 KB Output is correct
36 Correct 192 ms 53704 KB Output is correct
37 Correct 93 ms 49096 KB Output is correct
38 Correct 97 ms 49104 KB Output is correct
39 Correct 129 ms 56136 KB Output is correct
40 Correct 129 ms 56008 KB Output is correct
41 Correct 71 ms 47304 KB Output is correct
42 Correct 93 ms 48204 KB Output is correct
43 Correct 62 ms 47184 KB Output is correct
44 Correct 104 ms 51152 KB Output is correct
45 Correct 63 ms 47304 KB Output is correct
46 Correct 63 ms 47308 KB Output is correct
47 Correct 104 ms 51536 KB Output is correct
48 Correct 102 ms 51528 KB Output is correct
49 Correct 184 ms 51152 KB Output is correct
50 Correct 184 ms 51248 KB Output is correct
51 Correct 167 ms 57936 KB Output is correct
52 Correct 162 ms 57424 KB Output is correct
53 Correct 167 ms 49608 KB Output is correct
54 Correct 136 ms 50000 KB Output is correct
55 Correct 101 ms 48464 KB Output is correct
56 Correct 147 ms 52944 KB Output is correct
57 Correct 100 ms 48848 KB Output is correct
58 Correct 104 ms 49360 KB Output is correct
59 Correct 103 ms 51536 KB Output is correct