# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954505 |
2024-03-28T05:18:31 Z |
irmuun |
Horses (IOI15_horses) |
C++17 |
|
251 ms |
45560 KB |
#include<bits/stdc++.h>
#include "horses.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const int maxn=5e5+5,inf=1e9;
const ll mod=1e9+7;
int n;
int x[maxn],y[maxn];
struct segtreeX{
vector<int>d,Xmul;
void init(){
d.resize(4*n);
Xmul.resize(4*n);
build(1,0,n-1);
}
void build(int node,int l,int r){
if(l==r){
d[node]=x[l];
Xmul[node]=x[l];
return;
}
int mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
if(d[node*2]==inf+1||d[node*2+1]==inf+1){
d[node]=inf+1;
}
else if(1ll*d[node*2]*d[node*2+1]>(ll)inf){
d[node]=inf+1;
}
else{
d[node]=d[node*2]*d[node*2+1];
}
Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
}
int query(int node,int l,int r,int L,int R){
if(R<L||R<l||r<L) return 1;
if(L<=l&&r<=R){
return d[node];
}
int mid=(l+r)/2;
int val1=query(node*2,l,mid,L,R),val2=query(node*2+1,mid+1,r,L,R);
if(val1>inf||val2>inf){
return inf+1;
}
else if(1ll*val1*val2>(ll)inf){
return inf+1;
}
return val1*val2;
}
int product(int node,int l,int r,int L,int R){
if(R<L||R<l||r<L) return 1;
if(L<=l&&r<=R){
return Xmul[node];
}
int mid=(l+r)/2;
return (1ll*product(node*2,l,mid,L,R)*product(node*2+1,mid+1,r,L,R)%mod);
}
void update(int node,int l,int r,int pos,int val){
if(r>pos||pos<l) return;
if(l==r){
d[node]=val;
Xmul[node]=val;
return;
}
int mid=(l+r)/2;
update(node*2,l,mid,pos,val);
update(node*2+1,mid+1,r,pos,val);
Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
}
}sgx;
bool check(int i,int j){
assert(i<j);
int more=sgx.query(1,0,n-1,i+1,j);
if(more==inf+1){
return false;
}
return (1ll*y[i]>1ll*y[j]*more);
}
struct segtree{
vector<int>d;
void init(){
d.resize(4*n);
build(1,0,n-1);
}
void build(int node,int l,int r){
if(l==r){
d[node]=l;//index
return;
}
int mid=(l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
int ind1=d[node*2],ind2=d[node*2+1];
if(check(ind1,ind2)){
d[node]=ind1;
}
else{
d[node]=ind2;
}
}
int query(int node,int l,int r,int L,int R){
if(R<L||R<l||r<L) return 0;
if(L<=l&&r<=R){
return d[node];
}
int mid=(l+r)/2;
int val1=query(node*2,l,mid,L,R),val2=query(node*2+1,mid+1,r,L,R);
if(check(val1,val2)){
return val1;
}
return val2;
}
void update(int node,int l,int r,int pos){
if(r<pos||pos<l) return;
if(l==r){
d[node]=l;
return;
}
int mid=(l+r)/2;
update(node*2,l,mid,pos);
update(node*2+1,mid+1,r,pos);
int ind1=d[node*2],ind2=d[node*2+1];
if(check(ind1,ind2)){
d[node]=ind1;
}
else{
d[node]=ind2;
}
}
}sg;
int solve(){
int ind=sg.query(1,0,n-1,0,n-1);
return 1ll*sgx.product(1,0,n-1,0,ind)*y[ind]%mod;
}
int init(int N,int X[],int Y[]){
n=N;
for(int i=0;i<n;i++){
x[i]=X[i];
y[i]=Y[i];
}
sgx.init();
sg.init();
return solve();
}
int updateX(int pos,int val){
sgx.update(1,0,n-1,pos,val);
return solve();
}
int updateY(int pos,int val){
y[pos]=val;
sg.update(1,0,n-1,pos);
return solve();
}
Compilation message
horses.cpp: In member function 'void segtreeX::build(int, int, int)':
horses.cpp:44:51: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
44 | Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int segtreeX::product(int, int, int, int, int)':
horses.cpp:67:76: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
67 | return (1ll*product(node*2,l,mid,L,R)*product(node*2+1,mid+1,r,L,R)%mod);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'void segtreeX::update(int, int, int, int, int)':
horses.cpp:79:51: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
79 | Xmul[node]=1ll*Xmul[node*2]*Xmul[node*2+1]%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:147:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
147 | return 1ll*sgx.product(1,0,n-1,0,ind)*y[ind]%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2500 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2492 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2552 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
1 ms |
2496 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
32524 KB |
Output is correct |
2 |
Incorrect |
205 ms |
45560 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2496 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2500 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2500 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2496 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |