# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1036532 |
2024-07-27T13:35:43 Z |
vjudge1 |
Horses (IOI15_horses) |
C++17 |
|
1500 ms |
47184 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using lint=__int128_t;
const lint mod=1e9+7;
const int lim=5e5+100;
const int inf=1e9;
int mul(lint i,lint j){
return i*j%mod;
}
int n,*x,*y;
struct{
int tree[4*lim];
int P,VAL;
int update(int l,int r,int node){
if(l==r){
return tree[node]=VAL;
}
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return tree[node]=mul(update(l,mid,child),tree[child|1]);
return tree[node]=mul(tree[child],update(mid+1,r,child|1));
}
void update(int p,int val){
P=p,VAL=val;
update(0,n-1,1);
}
int query(int l,int r,int node){
if(r<=P){
return tree[node];
}
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return query(l,mid,child);
return mul(tree[child],query(mid+1,r,child|1));
}
int query(int p){
P=p;
return query(0,n-1,1);
}
}stmul;
struct{
int tree[4*lim];
int P,VAL;
int update(int l,int r,int node){
if(l==r)return tree[node]=VAL;
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return tree[node]=max(update(l,mid,child),tree[child|1]);
return tree[node]=max(tree[child],update(mid+1,r,child|1));
}
void update(int p,int val){
P=p,VAL=val;
update(0,n-1,1);
}
int L,R;
int query(int l,int r,int node){
if(L<=l&&r<=R)return tree[node];
if(r<L||R<l)return 0;
int mid=(l+r)>>1,child=node<<1;
return max(query(l,mid,child),query(mid+1,r,child|1));
}
int query(int l,int r){
L=l,R=r;
return query(0,n-1,1);
}
}stmax;
set<int,greater<int>>nonones;
int findmax(){
if(!nonones.size())return stmax.query(0,n-1);
int past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
int curbest=mul(aa,bb),temp=aa*x[past];
if(inf<temp)return curbest;
for(auto p=next(nonones.begin());p!=nonones.end();p++){
aa=stmax.query(*p,past-1);
if(temp<aa){
bb=stmul.query(*p);
curbest=mul(aa,bb);
temp=aa;
}
temp=temp*x[*p];
if(inf<temp)return curbest;
past=*p;
}
return curbest;
}
int init(int N, int X[], int Y[]) {
n=N,x=X,y=Y;
for(int i=0;i<n;i++){
stmul.update(i,x[i]);
stmax.update(i,y[i]);
if(X[i]!=1)nonones.insert(i);
}
return findmax();
}
int updateX(int pos, int val) {
if(x[pos]!=1)nonones.erase(pos);
x[pos]=val;
stmul.update(pos,val);
if(x[pos]!=1)nonones.insert(pos);
return findmax();
}
int updateY(int pos, int val) {
stmax.update(pos,val);
return findmax();
}
Compilation message
horses.cpp: In function 'int mul(lint, lint)':
horses.cpp:13:12: warning: conversion from 'lint' {aka '__int128'} to 'int' may change value [-Wconversion]
13 | return i*j%mod;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 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 |
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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 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 |
448 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 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 |
444 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 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 |
452 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
455 ms |
41000 KB |
Output is correct |
2 |
Execution timed out |
1595 ms |
47184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
408 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
448 KB |
Output is correct |
11 |
Correct |
1 ms |
444 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
436 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
444 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |