Submission #259347

# Submission time Handle Problem Language Result Execution time Memory
259347 2020-08-07T16:17:56 Z IOrtroiii Horses (IOI15_horses) C++14
100 / 100
344 ms 75000 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int MX = 1 << 19;

int N;
int X[MX], Y[MX];

pair<ld, int> best[MX << 2];
ld sum[MX << 2];

void pop(int v) {
   best[v] = max(best[v << 1], make_pair(best[v << 1 | 1].first + sum[v << 1], best[v << 1 | 1].second));
   sum[v] = sum[v << 1] + sum[v << 1 | 1];
}

void init(int v, int l, int r) {
   if (l == r) {
      best[v] = make_pair(log(X[l]) + log(Y[l]), l);
      sum[v] = log(X[l]);
      return;
   }
   int md = (l + r) >> 1;
   init(v << 1, l, md);
   init(v << 1 | 1, md + 1, r);
   pop(v);
}

void modify(int v, int l, int r, int p) {
   if (l == r) {
      best[v] = make_pair(log(X[l]) + log(Y[l]), l);
      sum[v] = log(X[l]);
      return;
   }
   int md = (l + r) >> 1;
   if (p <= md) modify(v << 1, l, md, p);
   else modify(v << 1 | 1, md + 1, r, p);
   pop(v);
}

const int MOD = 1000000007;

int mult(int x, int y) { return ll(x) * y % MOD; }
int st[MX << 2];

int _N;

void init() {
   _N = 1;
   while (_N < N) _N <<= 1;
   for (int i = 0; i < N; ++i) {
      st[_N + i] = X[i];
   }
   for (int i = _N - 1; i >= 1; --i) st[i] = mult(st[i << 1], st[i << 1 | 1]);
}

void modify(int p) {
   st[p + _N] = X[p];
   p += _N;
   for (p >>= 1; p > 0; p >>= 1) {
      st[p] = mult(st[p << 1], st[p << 1 | 1]);
   }
}

int query(int p) {
   int ans = Y[p];
   for (int l = _N, r = p + _N; l <= r; l >>= 1, r >>= 1) {
      if (l & 1) ans = mult(ans, st[l++]);
      if (!(r & 1)) ans = mult(ans, st[r--]);
   }
   return ans;
}

int init(int _N, int _X[], int _Y[]) {
   N = _N;
   for (int i = 0; i < N; ++i) X[i] = _X[i], Y[i] = _Y[i];
   init(1, 0, N - 1);
   init();
   return query(best[1].second);
}

int updateX(int pos, int val) {
   X[pos] = val;
   modify(1, 0, N - 1, pos);
   modify(pos);
   return query(best[1].second);
}

int updateY(int pos, int val) {
   Y[pos] = val;
   modify(1, 0, N - 1, pos);
   modify(pos);
   return query(best[1].second);
}

Compilation message

horses.cpp: In function 'int mult(int, int)':
horses.cpp:47:43: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
 int mult(int x, int y) { return ll(x) * y % MOD; }
                                 ~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:78:36: warning: declaration of '_N' shadows a global declaration [-Wshadow]
 int init(int _N, int _X[], int _Y[]) {
                                    ^
horses.cpp:50:5: note: shadowed declaration is here
 int _N;
     ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 0 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 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 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 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 0 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 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 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 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 66296 KB Output is correct
2 Correct 344 ms 75000 KB Output is correct
3 Correct 269 ms 66296 KB Output is correct
4 Correct 324 ms 70136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 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 384 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 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 0 ms 384 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 0 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 2 ms 544 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 512 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 111 ms 65528 KB Output is correct
34 Correct 121 ms 65528 KB Output is correct
35 Correct 156 ms 72712 KB Output is correct
36 Correct 159 ms 72440 KB Output is correct
37 Correct 87 ms 63608 KB Output is correct
38 Correct 119 ms 64544 KB Output is correct
39 Correct 68 ms 63480 KB Output is correct
40 Correct 121 ms 67448 KB Output is correct
41 Correct 67 ms 63608 KB Output is correct
42 Correct 69 ms 63864 KB Output is correct
43 Correct 117 ms 67960 KB Output is correct
44 Correct 113 ms 67832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 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 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 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 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 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 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 2 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 512 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 177 ms 66316 KB Output is correct
34 Correct 334 ms 74992 KB Output is correct
35 Correct 273 ms 66168 KB Output is correct
36 Correct 309 ms 70136 KB Output is correct
37 Correct 110 ms 65528 KB Output is correct
38 Correct 113 ms 65528 KB Output is correct
39 Correct 155 ms 72440 KB Output is correct
40 Correct 152 ms 72440 KB Output is correct
41 Correct 79 ms 63640 KB Output is correct
42 Correct 115 ms 64592 KB Output is correct
43 Correct 72 ms 63736 KB Output is correct
44 Correct 121 ms 67448 KB Output is correct
45 Correct 71 ms 63608 KB Output is correct
46 Correct 71 ms 63612 KB Output is correct
47 Correct 119 ms 67832 KB Output is correct
48 Correct 119 ms 67832 KB Output is correct
49 Correct 296 ms 67444 KB Output is correct
50 Correct 291 ms 67576 KB Output is correct
51 Correct 225 ms 74356 KB Output is correct
52 Correct 232 ms 73848 KB Output is correct
53 Correct 262 ms 65840 KB Output is correct
54 Correct 203 ms 66424 KB Output is correct
55 Correct 150 ms 64632 KB Output is correct
56 Correct 223 ms 69368 KB Output is correct
57 Correct 136 ms 65272 KB Output is correct
58 Correct 142 ms 65784 KB Output is correct
59 Correct 115 ms 67960 KB Output is correct