// In the name of Allah
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct node {
ll mul, val, valx;
ll ans, ansx;
};
const int maxn = (1 << 19) + 4;
const int maxlg = 20;
const int mod = 1e9 + 7;
const ll oo = 1e9 + 7;
int n; pll A[maxn];
node t[2 * maxn], ca;
int R; ll valx;
node f(node a, node b) {
node res;
res.mul = a.mul * b.mul % mod;
res.val = min(oo, a.val * b.val);
res.ans = min(oo, max(a.ans, a.val * b.ans));
res.valx = a.valx * b.valx;
res.ansx = max(a.ansx, a.valx * b.ansx);
return res;
}
void build(int v, int tl, int tr) {
if (tr - tl == 1) {
t[v].mul = A[tl].F; t[v].val = A[tl].F; t[v].valx = A[tl].F;
t[v].ans = min(oo, A[tl].F * A[tl].S);
t[v].ansx = A[tl].F * A[tl].S;
return ;
}
int mid = (tl + tr) / 2;
build(2 * v + 1, tl, mid); build(2 * v + 2, mid, tr);
t[v] = f(t[2 * v + 1], t[2 * v + 2]);
}
void upd(int v, int tl, int tr, int i) {
if (i >= tr || i < tl) return ;
if (tr - tl == 1) {
t[v].mul = A[tl].F; t[v].val = A[tl].F; t[v].valx = A[tl].F;
t[v].ans = min(oo, A[tl].F * A[tl].S);
t[v].ansx = A[tl].F * A[tl].S;
return ;
}
int mid = (tl + tr) / 2;
upd(2 * v + 1, tl, mid, i); upd(2 * v + 2, mid, tr, i);
t[v] = f(t[2 * v + 1], t[2 * v + 2]);
}
pll get_ind(int v, int tl, int tr) {
node res = ca;
while (tr - tl > 1) {
int mid = (tl + tr) / 2;
node resx = f(t[2 * v + 2], res);
if (resx.ans < oo) {
res = resx;
v = 2 * v + 1; tr = mid;
}
else {
v = 2 * v + 2; tl = mid;
}
}
res = f(t[v], res);
return Mp(tl, res.ansx);
}
ll get_mul(int v, int tl, int tr, int l, int r) {
l = max(l, tl); r = min(r, tr);
if (l >= tr || r <= tl) return ca.mul;
if (l == tl && r == tr) return t[v].mul;
int mid = (tl + tr) / 2;
return get_mul(2 * v + 1, tl, mid, l, r) * get_mul(2 * v + 2, mid, tr, l, r) % mod;
}
ll get_ans(int ind) {
if (ind >= R) {
auto f = get_ind(0, 0, n);
R = f.F; valx = f.S;
}
return valx * get_mul(0, 0, n, 0, R) % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < n; i++) A[i] = Mp(X[i], Y[i]);
ca.mul = 1; ca.val = 1; ca.valx = 1;
ca.ans = 1; ca.ansx = 1;
build(0, 0, n); R = -1;
return get_ans(n);
}
int updateX(int i, int val) {
A[i].F = val;
upd(0, 0, n, i);
return get_ans(i);
}
int updateY(int i, int val) {
A[i].S = val;
upd(0, 0, n, i);
return get_ans(i);
}
Compilation message
horses.cpp: In function 'll get_ans(int)':
horses.cpp:15:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
15 | #define F first
| ^
horses.cpp:103:9: note: in expansion of macro 'F'
103 | R = f.F; valx = f.S;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:114:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | return get_ans(n);
| ~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:120:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
120 | return get_ans(i);
| ~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:126:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
126 | return get_ans(i);
| ~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2500 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Incorrect |
1 ms |
2500 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
57940 KB |
Output is correct |
2 |
Incorrect |
134 ms |
66812 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2500 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Incorrect |
1 ms |
2440 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2652 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |