# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
726494 |
2023-04-19T03:06:20 Z |
becaido |
Horses (IOI15_horses) |
C++17 |
|
144 ms |
44292 KB |
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define lpos pos*2
#define rpos pos*2+1
const int MOD = 1e9 + 7;
const int SIZE = 5e5 + 5;
struct Node {
int pro = 1;
double sum = 0, mx = 0;
Node operator + (const Node& rhs) const {
Node re;
re.pro = 1ll * pro * rhs.pro % MOD;
re.sum = sum + rhs.sum;
re.mx = max(mx, sum + rhs.mx);
return re;
}
} node[4 * SIZE];
int n, y[SIZE];
void upd(int pos, int l, int r, int p, int ty, int x) {
if (l == r) {
if (ty == 1) {
node[pos].pro = x;
node[pos].sum = log(x);
}
if (ty == 2) {
node[pos].mx = node[pos].sum + log(y[p] = x);
}
return;
}
int mid = (l + r) / 2;
if (p <= mid) upd(lpos, l, mid, p, ty, x);
else upd(rpos, mid + 1, r, p, ty, x);
node[pos] = node[lpos] + node[rpos];
}
int que(int pos, int l, int r, int cur = 1) {
if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
int mid = (l + r) / 2;
if (node[lpos].mx >= node[lpos].sum + node[rpos].mx) return que(lpos, l, mid, cur);
else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
}
int init(int N, int X[], int Y[]) {
auto build = [&](auto build, int pos, int l, int r)->void {
if (l == r) {
node[pos].pro = X[l];
node[pos].sum = log(X[l]);
node[pos].mx = node[pos].sum + log(y[l] = Y[l]);
return;
}
int mid = (l + r) / 2;
build(build, lpos, l, mid);
build(build, rpos, mid + 1, r);
node[pos] = node[lpos] + node[rpos];
};
n = N;
build(build, 1, 0, n - 1);
return que(1, 0, n - 1);
}
int updateX(int pos, int val) {
upd(1, 0, n - 1, pos, 1, val);
return que(1, 0, n - 1);
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, 2, val);
return que(1, 0, n - 1);
}
Compilation message
horses.cpp: In member function 'Node Node::operator+(const Node&) const':
horses.cpp:16:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
16 | re.pro = 1ll * pro * rhs.pro % MOD;
| ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int que(int, int, int, int)':
horses.cpp:43:63: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
43 | if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:46:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
46 | else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In lambda function:
horses.cpp:50:27: warning: declaration of 'build' shadows a previous local [-Wshadow]
50 | auto build = [&](auto build, int pos, int l, int r)->void {
| ~~~~~^~~~~
horses.cpp:50:10: note: shadowed declaration is here
50 | auto build = [&](auto build, int pos, int l, int r)->void {
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
31872 KB |
Output is correct |
2 |
Correct |
144 ms |
44292 KB |
Output is correct |
3 |
Incorrect |
106 ms |
35532 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |