# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
299134 |
2020-09-14T13:54:51 Z |
Hemimor |
Horses (IOI15_horses) |
C++14 |
|
1163 ms |
52344 KB |
#include "horses.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
class Segment_Tree{
private:
int n;
vl date;
public:
void Init(int n_){
n=1;
while(n<n_) n*=2;
date=vl(2*n-1,1);
}
void Update(int k,int x){
k+=n-1;
date[k]=x;
while(k>0){
k=(k-1)/2;
date[k]=date[k*2+1]*date[k*2+2]%mod;
}
}
ll Query(int a,int b){
a+=n-1;b+=n-1;
ll m=1;
while(a<b){
if(a%2==0) (m*=date[a++])%=mod;
if(b%2==0) (m*=date[--b])%=mod;
a/=2;b/=2;
}
return m;
}
ll Open(int k){return date[k+n-1];}
};
template <class T>
class RMQ{
private:
int n;
vector<T> rmq;
T dfs(int a,int b,int k,int l,int r){
if(r<=a||b<=l) return 0;
if(a<=l&&r<=b) return rmq[k];
int m=(l+r)/2;
return max(dfs(a,b,k*2+1,l,m),dfs(a,b,k*2+2,m,r));
}
public:
void Init(int n_){
n=1;
while(n<n_) n*=2;
rmq=vector<T>(2*n-1);
}
void Update(int k,T x){
k+=n-1;
rmq[k]=x;
while(k>0){
k=(k-1)/2;
rmq[k]=max(rmq[k*2+1],rmq[k*2+2]);
}
}
T Query(int a,int b){
return dfs(a,b,0,0,n);
}
};
int n;
set<int> st;
RMQ<int> rmq;
Segment_Tree seg;
vi a,b;
int f(){
ll t=1,mx=0;
int id=n,tmp=0;
vi c;
while(t<=1000000000){
auto it=st.lower_bound(id);
if(it==st.begin()){
if(!c.empty()) tmp=rmq.Query(0,c.back());
break;
}
it--;
id=*it;
c.push_back(id);
t*=a[id];
// cout<<id<<' '<<a[id]<<' '<<t<<endl;
}
if(c.empty()) return rmq.Query(0,n);
reverse(c.begin(),c.end());
int m=(int)c.size();
t=1;
for(int i=0;i<m;i++){
if(i) t*=a[c[i]];
ll y=rmq.Query(c[i],(i==m-1?n:c[i+1]));
// cout<<t<<' '<<y<<' '<<c[i]<<' '<<(i==m-1?n:c[i+1])<<endl;
mx=max(mx,t*y);
}
mx%=mod;
return max(tmp,(int)(mx*seg.Query(0,c[0]+1)%mod));
}
int init(int N, int X[], int Y[]) {
n=N;
a=b=vi(n);
rmq.Init(N);
seg.Init(N);
for(int i=0;i<n;i++){
a[i]=X[i],b[i]=Y[i];
if(a[i]>1) st.insert(i);
seg.Update(i,a[i]);
rmq.Update(i,b[i]);
}
return f();
}
int updateX(int pos, int val){
if(a[pos]>1) st.erase(pos);
a[pos]=val;
if(a[pos]>1) st.insert(pos);
seg.Update(pos,val);
return f();
}
int updateY(int pos, int val) {
b[pos]=val;
rmq.Update(pos,val);
return f();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1163 ms |
45140 KB |
Output is correct |
2 |
Correct |
465 ms |
44920 KB |
Output is correct |
3 |
Correct |
487 ms |
45048 KB |
Output is correct |
4 |
Correct |
594 ms |
45048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
152 ms |
24696 KB |
Output is correct |
34 |
Correct |
147 ms |
24568 KB |
Output is correct |
35 |
Correct |
300 ms |
49660 KB |
Output is correct |
36 |
Correct |
283 ms |
49656 KB |
Output is correct |
37 |
Correct |
192 ms |
22776 KB |
Output is correct |
38 |
Correct |
227 ms |
35576 KB |
Output is correct |
39 |
Correct |
140 ms |
22528 KB |
Output is correct |
40 |
Correct |
268 ms |
49912 KB |
Output is correct |
41 |
Correct |
160 ms |
22648 KB |
Output is correct |
42 |
Correct |
174 ms |
22648 KB |
Output is correct |
43 |
Correct |
272 ms |
50296 KB |
Output is correct |
44 |
Correct |
258 ms |
50296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
1163 ms |
48804 KB |
Output is correct |
34 |
Correct |
547 ms |
49784 KB |
Output is correct |
35 |
Correct |
565 ms |
48736 KB |
Output is correct |
36 |
Correct |
734 ms |
52344 KB |
Output is correct |
37 |
Correct |
151 ms |
24568 KB |
Output is correct |
38 |
Correct |
147 ms |
24696 KB |
Output is correct |
39 |
Correct |
316 ms |
51064 KB |
Output is correct |
40 |
Correct |
291 ms |
50808 KB |
Output is correct |
41 |
Correct |
194 ms |
22776 KB |
Output is correct |
42 |
Correct |
235 ms |
35704 KB |
Output is correct |
43 |
Correct |
143 ms |
22528 KB |
Output is correct |
44 |
Correct |
282 ms |
50072 KB |
Output is correct |
45 |
Correct |
164 ms |
22648 KB |
Output is correct |
46 |
Correct |
177 ms |
22648 KB |
Output is correct |
47 |
Correct |
270 ms |
50468 KB |
Output is correct |
48 |
Correct |
270 ms |
50296 KB |
Output is correct |
49 |
Correct |
273 ms |
27768 KB |
Output is correct |
50 |
Correct |
248 ms |
27644 KB |
Output is correct |
51 |
Correct |
559 ms |
51312 KB |
Output is correct |
52 |
Correct |
392 ms |
51320 KB |
Output is correct |
53 |
Correct |
795 ms |
26156 KB |
Output is correct |
54 |
Correct |
524 ms |
39676 KB |
Output is correct |
55 |
Correct |
227 ms |
23592 KB |
Output is correct |
56 |
Correct |
375 ms |
51832 KB |
Output is correct |
57 |
Correct |
429 ms |
24312 KB |
Output is correct |
58 |
Correct |
552 ms |
24732 KB |
Output is correct |
59 |
Correct |
274 ms |
50348 KB |
Output is correct |