# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
204777 |
2020-02-27T05:55:34 Z |
TAISA_ |
Horses (IOI15_horses) |
C++14 |
|
1101 ms |
61048 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<int,int>;
int x[500000],y[500000];
int n;
const ll mod=1000000007LL;
struct segtree{
int n;
vector<ll> dat;
void build(int n_){
n=1;
while(n<n_)n<<=1;
dat.resize(2*n,1);
}
void upd(int k,ll s){
k+=n;
dat[k]=s%mod;
k>>=1;
while(k>0){
dat[k]=dat[k<<1]*dat[k<<1|1]%mod;
k>>=1;
}
}
ll get(int a,int b,int k,int l,int r){
if(b<=l||r<=a)return 1LL;
if(a<=l&&r<=b)return dat[k]%mod;
int m=(l+r)/2;
return get(a,b,k<<1,l,m)*get(a,b,k<<1|1,m,r)%mod;
}
ll get(int a,int b){return get(a,b,1,0,n);}
} seg;
struct RMQ{
int n;
vector<ll> dat;
void build(int n_){
n=1;
while(n<n_)n<<=1;
dat.resize(2*n,0);
}
void upd(int k,ll s){
k+=n;
dat[k]=s;
k>>=1;
while(k>0){
dat[k]=max(dat[k<<1],dat[k<<1|1]);
k>>=1;
}
}
ll get(int a,int b,int k,int l,int r){
if(b<=l||r<=a)return 0;
if(a<=l&&r<=b)return dat[k];
int m=(l+r)/2;
return max(get(a,b,k<<1,l,m),get(a,b,k<<1|1,m,r));
}
ll get(int a,int b){return get(a,b,1,0,n);}
} rmq;
set<P> st;
ll calc(){
ll id=-1,t=1,by=-1;
for(auto it=prev(st.end());;it--){
ll yy=rmq.get(it->first,it->second+1);
if(yy>t*by){
by=yy;
id=it->first;
t=1;
}
t*=x[it->first];
if(t>=mod)break;
if(it==st.begin())break;
}
return by*seg.get(0,id+1)%mod;
}
int init(int N, int X[], int Y[]) {
n=N;
seg.build(n+10);
rmq.build(n+10);
int l=0;
for(int i=0;i<n;i++){
x[i]=X[i];
y[i]=Y[i];
if(x[i]!=1){
if(i>0)st.insert(P(l,i-1));
l=i;
}
seg.upd(i,x[i]);
rmq.upd(i,y[i]);
}
st.insert(P(l,n-1));
return calc();
}
int updateX(int pos, int val) {
if(x[pos]==val)return calc();
if(x[pos]==1){
auto it=prev(st.lower_bound(P(pos+1,0)));
P p=(*it);
st.erase(it);
st.insert(P(pos,p.second));
if(p.first<pos)st.insert(P(p.first,pos-1));
}else if(val==1){
auto it=prev(st.lower_bound(P(pos+1,0)));
if(it!=st.begin()){
P p=(*it);
auto i2=prev(it);
P p2=(*i2);
st.erase(it);
st.erase(i2);
st.insert(P(p2.first,p.second));
}
}
x[pos]=val;
seg.upd(pos,val);
return calc();
}
int updateY(int pos, int val) {
y[pos]=val;
rmq.upd(pos,val);
return calc();
}
Compilation message
horses.cpp: In function 'll calc()':
horses.cpp:73:24: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return by*seg.get(0,id+1)%mod;
~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:91:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:28: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
if(x[pos]==val)return calc();
~~~~^~
horses.cpp:114:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:120:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
8 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1074 ms |
49168 KB |
Output is correct |
2 |
Correct |
379 ms |
49016 KB |
Output is correct |
3 |
Correct |
378 ms |
49144 KB |
Output is correct |
4 |
Correct |
426 ms |
49076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
7 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
504 KB |
Output is correct |
27 |
Correct |
8 ms |
380 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
380 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
7 ms |
376 KB |
Output is correct |
33 |
Correct |
142 ms |
24824 KB |
Output is correct |
34 |
Correct |
139 ms |
24824 KB |
Output is correct |
35 |
Correct |
315 ms |
48120 KB |
Output is correct |
36 |
Correct |
301 ms |
48120 KB |
Output is correct |
37 |
Correct |
183 ms |
24824 KB |
Output is correct |
38 |
Correct |
214 ms |
36856 KB |
Output is correct |
39 |
Correct |
129 ms |
24568 KB |
Output is correct |
40 |
Correct |
288 ms |
54136 KB |
Output is correct |
41 |
Correct |
156 ms |
26872 KB |
Output is correct |
42 |
Correct |
166 ms |
26872 KB |
Output is correct |
43 |
Correct |
282 ms |
54424 KB |
Output is correct |
44 |
Correct |
278 ms |
54392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
7 ms |
376 KB |
Output is correct |
32 |
Correct |
7 ms |
376 KB |
Output is correct |
33 |
Correct |
1101 ms |
49104 KB |
Output is correct |
34 |
Correct |
377 ms |
49104 KB |
Output is correct |
35 |
Correct |
372 ms |
49016 KB |
Output is correct |
36 |
Correct |
418 ms |
49144 KB |
Output is correct |
37 |
Correct |
140 ms |
24824 KB |
Output is correct |
38 |
Correct |
138 ms |
24952 KB |
Output is correct |
39 |
Correct |
308 ms |
48224 KB |
Output is correct |
40 |
Correct |
299 ms |
48120 KB |
Output is correct |
41 |
Correct |
173 ms |
24860 KB |
Output is correct |
42 |
Correct |
213 ms |
36600 KB |
Output is correct |
43 |
Correct |
128 ms |
24568 KB |
Output is correct |
44 |
Correct |
285 ms |
54136 KB |
Output is correct |
45 |
Correct |
148 ms |
26744 KB |
Output is correct |
46 |
Correct |
165 ms |
26744 KB |
Output is correct |
47 |
Correct |
283 ms |
54392 KB |
Output is correct |
48 |
Correct |
279 ms |
54520 KB |
Output is correct |
49 |
Correct |
251 ms |
31736 KB |
Output is correct |
50 |
Correct |
230 ms |
31736 KB |
Output is correct |
51 |
Correct |
446 ms |
61048 KB |
Output is correct |
52 |
Correct |
368 ms |
60536 KB |
Output is correct |
53 |
Correct |
696 ms |
30136 KB |
Output is correct |
54 |
Correct |
404 ms |
43896 KB |
Output is correct |
55 |
Correct |
206 ms |
27768 KB |
Output is correct |
56 |
Correct |
384 ms |
56056 KB |
Output is correct |
57 |
Correct |
454 ms |
28664 KB |
Output is correct |
58 |
Correct |
571 ms |
29128 KB |
Output is correct |
59 |
Correct |
283 ms |
54520 KB |
Output is correct |