# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
590784 |
2022-07-06T11:09:38 Z |
FatihSolak |
Horses (IOI15_horses) |
C++17 |
|
1500 ms |
56168 KB |
#include "horses.h"
#include <bits/stdc++.h>
#define N 500005
using namespace std;
const int mod = 1e9 + 7;
struct node{
pair<int,int> maxi;
int prod = 1;
node(pair<int,int> a,int b){
maxi = a;
prod = b;
}
};
node merge(node a,node b){
a.prod = (long long)a.prod * b.prod %mod;
a.maxi = max(a.maxi,b.maxi);
return a;
}
struct SegTree{
vector<node> t;
int n;
void init(int size){
n = size;
t.assign(4*n,node(make_pair(0,0),1));
}
void upd1(int v,int tl,int tr,int pos,int val){
if(tl == tr){
t[v].prod = val;
return;
}
int tm = (tl + tr)/2;
if(pos <= tm){
upd1(v*2,tl,tm,pos,val);
}
else upd1(v*2+1,tm+1,tr,pos,val);
t[v] = merge(t[v*2],t[v*2+1]);
}
void upd2(int v,int tl,int tr,int pos,int val){
if(tl == tr){
t[v].maxi = {val,pos};
return;
}
int tm = (tl + tr)/2;
if(pos <= tm){
upd2(v*2,tl,tm,pos,val);
}
else upd2(v*2+1,tm+1,tr,pos,val);
t[v] = merge(t[v*2],t[v*2+1]);
}
node get(int v,int tl,int tr,int l,int r){
if(tr < l || r < tl){
return node(make_pair(0,0),1);
}
if(l <= tl && tr <= r){
return t[v];
}
int tm = (tl + tr)/2;
return merge(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}
void upd1(int pos,int val){
upd1(1,0,n-1,pos,val);
}
void upd2(int pos,int val){
upd2(1,0,n-1,pos,val);
}
node get(int l,int r){
return get(1,0,n-1,l,r);
}
}tree;
const int BOUND = 1e9;
set<int> s;
int x[N],y[N];
int n;
int get_ans(){
int l = 0;
long long prod = 1;
if(s.size()){
auto it = prev(s.end());
while(prod < BOUND){
prod *= x[*it];
if(prod >= BOUND){
l = *it;
}
if(it == s.begin())break;
it = prev(it);
}
}
int tmp = l;
int opt = l;
long long val = 0;
prod = 1;
while(1){
if(l != tmp){
prod *= x[l];
}
auto foo = tree.get(l,n);
if(prod * foo.maxi.first > val){
val = prod * foo.maxi.first;
opt = foo.maxi.second;
}
if(s.upper_bound(l) == s.end())break;
l = *s.upper_bound(l);
}
return (long long)y[opt] * tree.get(0,opt).prod % mod;
}
int init(int n_, int X[], int Y[]) {
n = n_;
tree.init(n);
for(int i = 0;i<n;i++){
x[i] = X[i];
y[i] = Y[i];
tree.upd1(i,x[i]);
tree.upd2(i,y[i]);
if(x[i] > 1){
s.insert(i);
}
}
return get_ans();
}
int updateX(int pos, int val) {
if(x[pos] > 1){
s.erase(pos);
}
x[pos] = val;
tree.upd1(pos,x[pos]);
if(x[pos] > 1){
s.insert(pos);
}
return get_ans();
}
int updateY(int pos, int val) {
y[pos] = val;
tree.upd2(pos,y[pos]);
return get_ans();
}
Compilation message
horses.cpp: In function 'node merge(node, node)':
horses.cpp:15:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
15 | a.prod = (long long)a.prod * b.prod %mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int get_ans()':
horses.cpp:104:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
104 | return (long long)y[opt] * tree.get(0,opt).prod % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1593 ms |
56080 KB |
Time limit exceeded |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
5 ms |
340 KB |
Output is correct |
33 |
Correct |
278 ms |
31824 KB |
Output is correct |
34 |
Correct |
270 ms |
31784 KB |
Output is correct |
35 |
Correct |
426 ms |
55240 KB |
Output is correct |
36 |
Correct |
380 ms |
55168 KB |
Output is correct |
37 |
Correct |
329 ms |
31708 KB |
Output is correct |
38 |
Correct |
357 ms |
43676 KB |
Output is correct |
39 |
Correct |
267 ms |
31572 KB |
Output is correct |
40 |
Correct |
375 ms |
55168 KB |
Output is correct |
41 |
Correct |
300 ms |
31764 KB |
Output is correct |
42 |
Correct |
323 ms |
31668 KB |
Output is correct |
43 |
Correct |
356 ms |
55032 KB |
Output is correct |
44 |
Correct |
375 ms |
55000 KB |
Output is correct |
# |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
388 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1588 ms |
56168 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |