# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1039986 |
2024-07-31T13:25:05 Z |
c2zi6 |
말 (IOI15_horses) |
C++14 |
|
1500 ms |
65624 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 SEGTREEPROD {
int n;
VL tree;
SEGTREEPROD(){}
SEGTREEPROD(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);
}
};
struct SEGTREEMAX {
int n;
VL tree;
SEGTREEMAX(){}
SEGTREEMAX(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] = max(tree[2*N+1], tree[2*N+2]);
}
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 -2e9;
int M = (L + R) / 2;
return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
}
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);
}
};
int n;
VL a, b;
SEGTREEPROD sega;
SEGTREEMAX segb;
set<int> nonone;
ll recalc() {
ll leave = n-1;
ll prod = 1;
reprl(i, n-1, 0) {
if (a[i] == 1) {
if (i != 0) {
continue;
}
}
/*for (auto it = prev(nonone.end()); it != nonone.begin(); it--) {*/
/* int i = *it;*/
ll bi = segb.get(i, n-1);
if (bi > prod) {
prod = a[i] * bi;
leave = i;
} else {
prod = a[i] * prod;
}
if (prod > 1e9) break;
}
/*if (a[0] == 1) {*/
/* int i = 0;*/
/* ll bi = segb.get(i, n-1);*/
/* if (bi > prod) {*/
/* prod = a[i] * bi;*/
/* leave = i;*/
/* } else {*/
/* prod = a[i] * prod;*/
/* }*/
/*}*/
return 1ll * sega.get(0, leave) * segb.get(leave, n-1) % MOD;
return sega.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];
}
sega = SEGTREEPROD(n);
rep(i, n) sega.upd(i, a[i]);
segb = SEGTREEMAX(n);
rep(i, n) segb.upd(i, b[i]);
rep(i, n) if (a[i] != 1) nonone.insert(i);
return recalc();
}
int updateX(int pos, int val) {
if (a[pos] != 1) nonone.erase(pos);
a[pos] = val;
if (a[pos] != 1) nonone.insert(pos);
sega.upd(pos, a[pos]);
return recalc();
}
int updateY(int pos, int val) {
b[pos] = val;
segb.upd(pos, b[pos]);
return recalc();
}
Compilation message
horses.cpp: In member function 'int SEGTREEPROD::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 member function 'int SEGTREEMAX::get(int, int, int, int, int)':
horses.cpp:90: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]
90 | if (l <= L && R <= r) return tree[N];
| ^
horses.cpp: In function 'll recalc()':
horses.cpp:127:13: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
127 | if (prod > 1e9) break;
| ^~~~
horses.cpp:140:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
140 | return 1ll * sega.get(0, leave) * segb.get(leave, n-1) % MOD;
| ^~~~~
horses.cpp:140:45: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
140 | return 1ll * sega.get(0, leave) * segb.get(leave, n-1) % MOD;
| ^~~~~
horses.cpp:141:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
141 | return sega.get(0, leave) * b[leave] % MOD;
| ^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:152:31: 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]
152 | rep(i, n) sega.upd(i, a[i]);
| ^
horses.cpp:154:31: 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]
154 | rep(i, n) segb.upd(i, b[i]);
| ^
horses.cpp:156:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
156 | return recalc();
| ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:163:25: 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]
163 | sega.upd(pos, a[pos]);
| ^
horses.cpp:164:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
164 | return recalc();
| ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:169:25: 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]
169 | segb.upd(pos, b[pos]);
| ^
horses.cpp:170:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
170 | return recalc();
| ~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
440 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 |
432 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
352 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
352 KB |
Output is correct |
13 |
Correct |
0 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
0 ms |
352 KB |
Output is correct |
16 |
Correct |
0 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
352 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
0 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
352 KB |
Output is correct |
25 |
Correct |
1 ms |
484 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
540 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
56940 KB |
Output is correct |
2 |
Correct |
313 ms |
65624 KB |
Output is correct |
3 |
Correct |
313 ms |
56724 KB |
Output is correct |
4 |
Correct |
318 ms |
60684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
412 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 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 |
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 |
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 |
2 ms |
516 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
448 KB |
Output is correct |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
129 ms |
32628 KB |
Output is correct |
34 |
Correct |
122 ms |
32496 KB |
Output is correct |
35 |
Correct |
217 ms |
62804 KB |
Output is correct |
36 |
Correct |
220 ms |
62940 KB |
Output is correct |
37 |
Correct |
252 ms |
30804 KB |
Output is correct |
38 |
Correct |
157 ms |
43604 KB |
Output is correct |
39 |
Execution timed out |
1587 ms |
30544 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
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 |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
349 ms |
56840 KB |
Output is correct |
34 |
Correct |
315 ms |
65616 KB |
Output is correct |
35 |
Correct |
292 ms |
56660 KB |
Output is correct |
36 |
Correct |
326 ms |
60684 KB |
Output is correct |
37 |
Correct |
130 ms |
32596 KB |
Output is correct |
38 |
Correct |
121 ms |
32504 KB |
Output is correct |
39 |
Correct |
220 ms |
62804 KB |
Output is correct |
40 |
Correct |
214 ms |
62748 KB |
Output is correct |
41 |
Correct |
270 ms |
30804 KB |
Output is correct |
42 |
Correct |
163 ms |
43616 KB |
Output is correct |
43 |
Execution timed out |
1534 ms |
30652 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |