# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
999635 |
2024-06-16T01:31:53 Z |
Alfraganus |
Horses (IOI15_horses) |
C++17 |
|
1500 ms |
16724 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<int> x, y;
struct SegTree {
int size = 1;
vector<long long> pr;
void init(){
while(size < (int)x.size())
size <<= 1;
pr.resize(size << 1, 1);
build(0, 0, size);
}
void build(int ind, int lx, int rx){
if(lx + 1 == rx){
if(lx < x.size())
pr[ind] = x[lx];
return;
}
int mid = (lx + rx) >> 1;
build((ind << 1) + 1, lx, mid);
build((ind << 1) + 2, mid, rx);
pr[ind] = (pr[(ind << 1) + 1] * pr[(ind << 1) + 2]) % mod;
}
long long get(int l, int r, int ind, int lx, int rx){
if(l <= lx and rx <= r)
return pr[ind];
if(r <= lx or rx <= l)
return 1;
int mid = (lx + rx) >> 1;
return (get(l, r, (1 << ind) + 1, lx, mid) * get(l, r, (1 << ind) + 2, mid, rx)) % mod;
}
int get(int l, int r){
return get(l, r, 0, 0, size);
}
};
SegTree s;
int init(int n, int X[], int Y[]) {
x.resize(n);
y.resize(n);
for(int i = 0; i < n; i ++)
x[i] = X[i], y[i] = Y[i];
s.init();
long long y1 = 0, p = 1, ans = 1;
for(int i = n - 1; i >= 0; i --){
p = p * x[i];
if(p > 1e9)
return ans;
if(y[i] > y1 * p){
y1 = y[i];
p = 1;
ans = (y1 * s.get(0, i + 1)) % mod;
}
}
return ans;
}
int updateX(int pos, int val) {
x[pos] = val;
long long ans = 1, p = 1;
for(int i = 0; i < (int)x.size(); i ++)
p = (p * x[i]) % mod, ans = (max(ans, p * y[i])) % mod;
int res = ans;
return res;
}
int updateY(int pos, int val) {
y[pos] = val;
long long ans = 1, p = 1;
for(int i = 0; i < (int)y.size(); i ++)
p = (p * x[i]) % mod, ans = (max(ans, p * y[i])) % mod;
int res = ans;
return res;
}
Compilation message
horses.cpp: In member function 'void SegTree::build(int, int, int)':
horses.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(lx < x.size())
| ~~~^~~~~~~~~~
horses.cpp: In member function 'int SegTree::get(int, int)':
horses.cpp:42:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | return get(l, r, 0, 0, size);
| ~~~^~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:57:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
57 | if(p > 1e9)
| ^
horses.cpp:58:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
58 | return ans;
| ^~~
horses.cpp:65:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
65 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:73:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
73 | int res = ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:82:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | int res = ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1513 ms |
16724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |