# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
852051 |
2023-09-21T07:34:57 Z |
ntkphong |
Horses (IOI15_horses) |
C++14 |
|
0 ms |
0 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long lim = 1e9 + 1;
const long long mod = 1e9 + 7;
const int mxN = 5e5 + 10;
int n;
long long aX[mxN], aY[mxN];
long long mul(long long x, long long y) {
return min(x * y, lim);
}
struct Node {
int id;
long long p, s;
long long np, ns;
friend Node operator + (Node a, Node b) {
Node c;
long long suffix = mul(a.s, b.p);
if(aY[a.id] > mul(suffix, aY[b.id])) {
c.id = a.id;
c.p = a.p;
c.s = mul(a.s, mul(b.p, b.s));
c.np = a.np;
c.ns = a.ns * b.np % mod * b.ns % mod;
} else {
c.id = b.id;
c.p = mul(mul(a.p, a.s), b.p);
c.s = b.s;
c.np = a.np * a.ns % mod * b.np % mod;
c.ns = b.ns;
}
return c;
}
} ST[mxN << 2];
void build(int id, int l, int r) {
if(l == r) {
ST[id] = {l, aX[l], 1, aX[l], 1};
return ;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
void update(int id, int l, int r, int x) {
if(r < x || x < l) return ;
if(l == r) {
ST[id] = {l, aX[l], 1, aX[l], 1};
return ;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, x);
update(id * 2 + 1, mid + 1, r, x);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
long long init(int N, vector<int> X, vector<int> Y) {
n = N;
for(int i = 0; i < N; i ++) aX[i] = X[i];
for(int i = 0; i < N; i ++) aY[i] = Y[i];
build(1, 0, N - 1);
return ST[1].np * aY[ST[1].id] % mod;
}
long long updateX(int pos, int val) {
aX[pos] = val;
update(1, 0, n - 1, pos);
return ST[1].np * aY[ST[1].id] % mod;
}
long long updateY(int pos, int val) {
aY[pos] = val;
update(1, 0, n - 1, pos);
return ST[1].np * aY[ST[1].id] % mod;
}
Compilation message
horses.cpp:79:11: error: ambiguating new declaration of 'long long int updateX(int, int)'
79 | long long updateX(int pos, int val) {
| ^~~~~~~
In file included from horses.cpp:1:
horses.h:5:5: note: old declaration 'int updateX(int, int)'
5 | int updateX(int pos, int val);
| ^~~~~~~
horses.cpp:85:11: error: ambiguating new declaration of 'long long int updateY(int, int)'
85 | long long updateY(int pos, int val) {
| ^~~~~~~
In file included from horses.cpp:1:
horses.h:6:5: note: old declaration 'int updateY(int, int)'
6 | int updateY(int pos, int val);
| ^~~~~~~