# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1018611 |
2024-07-10T07:26:17 Z |
AmirAli_H1 |
Horses (IOI15_horses) |
C++17 |
|
810 ms |
25492 KB |
// In the name of Allah
#include <bits/stdc++.h>
#include "horses.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
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 {
int mul, mx, ind;
};
const int maxn = (1 << 19) + 4;
const int maxlg = 20;
const int mod = 1e9 + 7;
int n; pll A[maxn];
node t[2 * maxn], ca;
int R; ll valx, lst;
node f(node a, node b) {
node res;
res.mul = 1ll * a.mul * b.mul % mod;
res.mx = max(a.mx, b.mx);
res.ind = max(a.ind, b.ind);
return res;
}
pii fx(pii a, pii b) {
return Mp(max(a.F, b.F), max(a.S, b.S));
}
void build(int v, int tl, int tr) {
if (tr - tl == 1) {
t[v].mul = A[tl].F; t[v].mx = A[tl].S;
if (A[tl].F == 1) t[v].ind = -1;
else t[v].ind = tl;
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].mx = A[tl].S;
if (A[tl].F == 1) t[v].ind = -1;
else t[v].ind = tl;
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_res(int v, int tl, int tr, int l, int r) {
l = max(l, tl); r = min(r, tr);
if (l >= tr || r <= tl) return Mp(ca.mx, ca.ind);
if (l == tl && r == tr) return Mp(t[v].mx, t[v].ind);
int mid = (tl + tr) / 2;
return fx(get_res(2 * v + 1, tl, mid, l, r), get_res(2 * v + 2, mid, tr, l, r));
}
int get_mul(int v, int tl, int tr, int r) {
r = min(r, tr);
if (r <= tl) return ca.mul;
if (r == tr) return t[v].mul;
int mid = (tl + tr) / 2;
if (r <= mid) return get_mul(2 * v + 1, tl, mid, r);
else return 1ll * t[2 * v + 1].mul * get_mul(2 * v + 2, mid, tr, r) % mod;
}
ll get_ans(int ind) {
if (ind >= R) {
ll mx = 1; int j = n;
while (j > 0) {
pll res = get_res(0, 0, n, 0, j);
int k = res.S;
if (k == -1) {
mx = max(mx, res.F); j = 0;
}
else {
res = get_res(0, 0, n, k, j);
mx = max(mx, (ll) res.F) * A[k].F; j = k;
if (mx >= mod) break;
}
}
R = j; valx = mx % mod;
}
return valx * get_mul(0, 0, n, 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.mx = 0; ca.ind = -1;
build(0, 0, n); R = -1;
return lst = get_ans(n);
}
int updateX(int i, int val) {
if (A[i].F == val) return lst;
A[i].F = val;
upd(0, 0, n, i);
return lst = get_ans(i);
}
int updateY(int i, int val) {
if (A[i].S == val) return lst;
A[i].S = val;
upd(0, 0, n, i);
return lst = get_ans(i);
}
Compilation message
horses.cpp: In function 'node f(node, node)':
horses.cpp:42:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | res.mul = 1ll * a.mul * b.mul % mod;
| ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:17:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
17 | #define F first
| ^
horses.cpp:54:20: note: in expansion of macro 'F'
54 | t[v].mul = A[tl].F; t[v].mx = A[tl].S;
| ^
horses.cpp:18:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | #define S second
| ^
horses.cpp:54:39: note: in expansion of macro 'S'
54 | t[v].mul = A[tl].F; t[v].mx = A[tl].S;
| ^
horses.cpp: In function 'void upd(int, int, int, int)':
horses.cpp:17:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
17 | #define F first
| ^
horses.cpp:67:20: note: in expansion of macro 'F'
67 | t[v].mul = A[tl].F; t[v].mx = A[tl].S;
| ^
horses.cpp:18:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | #define S second
| ^
horses.cpp:67:39: note: in expansion of macro 'S'
67 | t[v].mul = A[tl].F; t[v].mx = A[tl].S;
| ^
horses.cpp: In function 'int get_mul(int, int, int, int)':
horses.cpp:91:70: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | else return 1ll * t[2 * v + 1].mul * get_mul(2 * v + 2, mid, tr, r) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'll get_ans(int)':
horses.cpp:18:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | #define S second
| ^
horses.cpp:99:16: note: in expansion of macro 'S'
99 | int k = res.S;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:119:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
119 | return lst = get_ans(n);
| ~~~~^~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:123:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
123 | if (A[i].F == val) return lst;
| ^~~
horses.cpp:126:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
126 | return lst = get_ans(i);
| ~~~~^~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:130:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
130 | if (A[i].S == val) return lst;
| ^~~
horses.cpp:133:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
133 | return lst = get_ans(i);
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
2392 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 |
0 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 |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
4 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
25328 KB |
Output is correct |
2 |
Correct |
90 ms |
25292 KB |
Output is correct |
3 |
Correct |
63 ms |
25444 KB |
Output is correct |
4 |
Correct |
74 ms |
25260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
2556 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2392 KB |
Output is correct |
19 |
Correct |
0 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 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2392 KB |
Output is correct |
32 |
Correct |
4 ms |
2392 KB |
Output is correct |
33 |
Correct |
27 ms |
24400 KB |
Output is correct |
34 |
Correct |
25 ms |
24408 KB |
Output is correct |
35 |
Correct |
51 ms |
24576 KB |
Output is correct |
36 |
Correct |
43 ms |
24400 KB |
Output is correct |
37 |
Correct |
19 ms |
24408 KB |
Output is correct |
38 |
Correct |
20 ms |
24548 KB |
Output is correct |
39 |
Correct |
19 ms |
24528 KB |
Output is correct |
40 |
Correct |
32 ms |
24400 KB |
Output is correct |
41 |
Correct |
65 ms |
24408 KB |
Output is correct |
42 |
Correct |
89 ms |
24520 KB |
Output is correct |
43 |
Correct |
28 ms |
24408 KB |
Output is correct |
44 |
Correct |
28 ms |
24488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 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 |
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 |
0 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 |
1 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 |
0 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 |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
4 ms |
2396 KB |
Output is correct |
33 |
Correct |
225 ms |
25424 KB |
Output is correct |
34 |
Correct |
103 ms |
25424 KB |
Output is correct |
35 |
Correct |
63 ms |
25312 KB |
Output is correct |
36 |
Correct |
76 ms |
25492 KB |
Output is correct |
37 |
Correct |
25 ms |
24408 KB |
Output is correct |
38 |
Correct |
27 ms |
24412 KB |
Output is correct |
39 |
Correct |
62 ms |
24496 KB |
Output is correct |
40 |
Correct |
46 ms |
24364 KB |
Output is correct |
41 |
Correct |
21 ms |
24408 KB |
Output is correct |
42 |
Correct |
20 ms |
24412 KB |
Output is correct |
43 |
Correct |
22 ms |
24412 KB |
Output is correct |
44 |
Correct |
32 ms |
24412 KB |
Output is correct |
45 |
Correct |
74 ms |
24412 KB |
Output is correct |
46 |
Correct |
92 ms |
24408 KB |
Output is correct |
47 |
Correct |
30 ms |
24412 KB |
Output is correct |
48 |
Correct |
28 ms |
24408 KB |
Output is correct |
49 |
Correct |
63 ms |
25460 KB |
Output is correct |
50 |
Correct |
67 ms |
25424 KB |
Output is correct |
51 |
Correct |
151 ms |
25428 KB |
Output is correct |
52 |
Correct |
69 ms |
25444 KB |
Output is correct |
53 |
Correct |
64 ms |
25320 KB |
Output is correct |
54 |
Correct |
45 ms |
25172 KB |
Output is correct |
55 |
Correct |
83 ms |
24524 KB |
Output is correct |
56 |
Correct |
91 ms |
25428 KB |
Output is correct |
57 |
Correct |
551 ms |
25456 KB |
Output is correct |
58 |
Correct |
810 ms |
25436 KB |
Output is correct |
59 |
Correct |
31 ms |
24484 KB |
Output is correct |