# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796657 |
2023-07-28T15:23:45 Z |
jasmin |
Horses (IOI15_horses) |
C++17 |
|
773 ms |
51976 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
int n=0;
vector<int> x;
vector<int> y;
const int MOD=1e9+7;
int MUL(int a, int b){
return (a*b)%MOD;
}
struct maxsegtree{
vector<int> tree;
void init(){
tree.assign(n*4, 0);
}
int update(int l, int r, int v, int x, int val){
if(x<l || r<=x) return tree[v];
if(l+1==r){
return tree[v]=val;
}
int m=l+(r-l)/2;
return tree[v]=max(update(l, m, v*2+1, x, val), update(m, r, v*2+2, x, val));
}
int query(int l, int r, int v, int ql, int qr){
if(qr<=l || r<=ql) return 0;
if(ql<=l && r<=qr){
return tree[v];
}
int m=l+(r-l)/2;
return max(query(l, m, v*2+1, ql, qr), query(m, r, v*2+2, ql, qr));
}
};
maxsegtree maxseg;
struct productsegtree{
vector<int> tree;
void init(){
tree.assign(n*4, 1);
}
int update(int l, int r, int v, int x, int val){
if(x<l || r<=x) return tree[v];
if(l+1==r){
return tree[v]=val;
}
int m=l+(r-l)/2;
return tree[v] = MUL(update(l, m, v*2+1, x, val), update(m, r, v*2+2, x, val));
}
int query(int l, int r, int v, int ql, int qr){
if(qr<=l || r<=ql) return 1;
if(ql<=l && r<=qr){
return tree[v];
}
int m=l+(r-l)/2;
return MUL(query(l, m, v*2+1, ql, qr), query(m, r, v*2+2, ql, qr));
}
};
productsegtree pseg;
set<int> notone;
int solve(){
bool mod=false;
auto it=notone.end();
long long product=1;
long long ans=1;
while(!mod && it!=notone.begin()){
it=prev(it);
int pos=*it;
product*=x[pos];
if(product>MOD){
product%=MOD;
mod=true;
break;
}
int yfac=maxseg.query(0, n, 0, pos, n);
int xfac=pseg.query(0, n, 0, 0, pos+1);
ans = max(ans, (long long)MUL(xfac, yfac));
}
return ans;
}
int init(int N, int X[], int Y[]) {
n=N;
x.assign(n, 0);
for(int i=0; i<n; i++){
x[i]=X[i];
}
y.assign(n, 0);
for(int i=0; i<n; i++){
y[i]=Y[i];
}
maxseg.init();
for(int i=0; i<n; i++){
maxseg.update(0, n, 0, i, y[i]);
}
pseg.init();
for(int i=0; i<n; i++){
pseg.update(0, n, 0, i, x[i]);
}
for(int i=0; i<n; i++){
if(x[i]!=1){
notone.insert(i);
}
}
return solve();
}
int updateX(int pos, int val) {
if(x[pos]==1 && val!=1){
notone.insert(pos);
}
if(x[pos]!=1 && val==1){
notone.erase(pos);
}
x[pos]=val;
pseg.update(0, n, 0, pos, val);
return solve();
}
int updateY(int pos, int val) {
y[pos]=val;
maxseg.update(0, n, 0, pos, val);
return solve();
}
Compilation message
horses.cpp: In member function 'int maxsegtree::update(int, int, int, int, int)':
horses.cpp:22:41: warning: declaration of 'x' shadows a global declaration [-Wshadow]
22 | int update(int l, int r, int v, int x, int val){
| ~~~~^
horses.cpp:6:13: note: shadowed declaration is here
6 | vector<int> x;
| ^
horses.cpp: In member function 'int productsegtree::update(int, int, int, int, int)':
horses.cpp:49:41: warning: declaration of 'x' shadows a global declaration [-Wshadow]
49 | int update(int l, int r, int v, int x, int val){
| ~~~~^
horses.cpp:6:13: note: shadowed declaration is here
6 | vector<int> x;
| ^
horses.cpp: In function 'int solve()':
horses.cpp:96:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
96 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
773 ms |
51976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |