# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1039822 |
2024-07-31T09:52:27 Z |
c2zi6 |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
33876 KB |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "horses.h"
const ll MOD = 1e9 + 7;
struct SEGTREE {
int n;
VL tree;
SEGTREE(){}
SEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
tree = VL(2*n);
}
void upd(int N, int L, int R, int i, int s) {
if (i < L || i > R) return;
if (L == R) {
tree[N] = s;
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, i, s);
upd(2*N+2, M+1, R, i, s);
tree[N] = tree[2*N+1] * tree[2*N+2] % MOD;
}
int get(int N, int L, int R, int l, int r) {
if (l <= L && R <= r) return tree[N];
if (R < l || L > r) return 1;
int M = (L + R) / 2;
return 1ll * get(2*N+1, L, M, l, r) * get(2*N+2, M+1, R, l, r) % MOD;
}
void upd(int i, int s) {
upd(0, 0, n-1, i, s);
}
int get(int l, int r) {
return get(0, 0, n-1, l, r);
}
} seg;
int n;
VL a, b;
ll recalc() {
ll leave = n-1;
ll prod = 1;
reprl(i, n-1, 0) {
if (b[i] > prod) {
prod = a[i] * b[i];
leave = i;
} else {
prod = a[i] * prod;
}
if (prod > 1e9) break;
}
return seg.get(0, leave) * b[leave] % MOD;
}
int init(int N, int X[], int Y[]) {
n = N;
a = b = VL(n);
rep(i, n) {
a[i] = X[i];
b[i] = Y[i];
}
seg = SEGTREE(n);
rep(i, n) seg.upd(i, a[i]);
return recalc();
}
int updateX(int pos, int val) {
a[pos] = val;
seg.upd(pos, a[pos]);
return recalc();
}
int updateY(int pos, int val) {
b[pos] = val;
return recalc();
}
Compilation message
horses.cpp: In member function 'int SEGTREE::get(int, int, int, int, int)':
horses.cpp:57:44: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
57 | if (l <= L && R <= r) return tree[N];
| ^
horses.cpp:60:72: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
60 | return 1ll * get(2*N+1, L, M, l, r) * get(2*N+2, M+1, R, l, r) % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'll recalc()':
horses.cpp:83:13: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
83 | if (prod > 1e9) break;
| ^~~~
horses.cpp:85:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
85 | return seg.get(0, leave) * b[leave] % MOD;
| ^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:96:30: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
96 | rep(i, n) seg.upd(i, a[i]);
| ^
horses.cpp:97:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
97 | return recalc();
| ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:102:24: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
102 | seg.upd(pos, a[pos]);
| ^
horses.cpp:103:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
103 | return recalc();
| ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:108:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
108 | return recalc();
| ~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
388 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
388 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
392 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
21148 KB |
Output is correct |
2 |
Correct |
151 ms |
33876 KB |
Output is correct |
3 |
Correct |
129 ms |
25100 KB |
Output is correct |
4 |
Correct |
148 ms |
29012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
356 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
109 ms |
20404 KB |
Output is correct |
34 |
Correct |
95 ms |
24404 KB |
Output is correct |
35 |
Correct |
121 ms |
31316 KB |
Output is correct |
36 |
Correct |
117 ms |
31160 KB |
Output is correct |
37 |
Correct |
290 ms |
22360 KB |
Output is correct |
38 |
Correct |
90 ms |
23396 KB |
Output is correct |
39 |
Execution timed out |
1563 ms |
22456 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
376 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
118 ms |
22868 KB |
Output is correct |
34 |
Correct |
151 ms |
33692 KB |
Output is correct |
35 |
Correct |
122 ms |
25108 KB |
Output is correct |
36 |
Correct |
158 ms |
29008 KB |
Output is correct |
37 |
Correct |
114 ms |
24312 KB |
Output is correct |
38 |
Correct |
96 ms |
24400 KB |
Output is correct |
39 |
Correct |
117 ms |
31236 KB |
Output is correct |
40 |
Correct |
117 ms |
31280 KB |
Output is correct |
41 |
Correct |
288 ms |
22488 KB |
Output is correct |
42 |
Correct |
92 ms |
23636 KB |
Output is correct |
43 |
Execution timed out |
1554 ms |
22692 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |