# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43594 |
2018-03-18T04:22:58 Z |
gnoor |
Horses (IOI15_horses) |
C++14 |
|
309 ms |
146536 KB |
#include "horses.h"
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int mod = 1000000007;
struct number {
long long val;
bool overflow;
number() {
val=0;
overflow=false;
}
number(long long _val) {
val=_val;
overflow=false;
}
number(long long _val,bool _of) {
val=_val;
overflow=_of;
}
bool operator< (const number &r) const {
if (overflow||r.overflow) {
return r.overflow;
}
return val<r.val;
}
number operator+(const number &r) const {
return number((val+r.val)%mod,(val+r.val)>=mod||overflow||r.overflow);
}
number operator-(const number &r) const {
return number(((val-r.val)%mod+mod)%mod,(val-r.val)<0||overflow||r.overflow);
}
number operator*(const number &r) const {
return number((val*r.val)%mod,(val*r.val)>=mod||overflow||r.overflow);
}
number& operator=(const long long _val) {
val=_val%mod;
overflow=_val>=mod;
return *this;
}
};
struct node {
number xval;
number ymax;
number pre;
number suf;
void combine(const node &l,const node &r) {
xval=l.xval*r.xval;
if (l.ymax<l.suf*r.pre*r.ymax) {
//choose right
ymax=r.ymax;
pre=l.xval*r.pre;
suf=r.suf;
} else {
//choose left
ymax=l.ymax;
pre=l.pre;
suf=l.suf*r.xval;
}
}
};
node seg[2000100];
number x[500100];
number y[500100];
int n;
void build(int idx,int l,int r) {
if (l+1==r) {
seg[idx].xval=x[l];
seg[idx].pre=x[l];
seg[idx].suf=1;
seg[idx].ymax=y[l];
return;
}
int m=(l+r)>>1;
build(idx*2+1,l,m);
build(idx*2+2,m,r);
seg[idx].combine(seg[idx*2+1],seg[idx*2+2]);
}
void update(int idx,int l,int r,int k) {
if (k<l||k>=r) return;
if (l+1==r) {
seg[idx].xval=x[l];
seg[idx].pre=x[l];
seg[idx].suf=1;
seg[idx].ymax=y[l];
return;
}
int m=(l+r)>>1;
update(idx*2+1,l,m,k);
update(idx*2+2,m,r,k);
seg[idx].combine(seg[idx*2+1],seg[idx*2+2]);
}
//void print(int idx,int l,int r) {
//printf("%d %d: %lld %lld %lld %lld\n",l,r,seg[idx].xval.val,seg[idx].ymax.val,seg[idx].suf.val,seg[idx].pre.val);
//if (l+1==r) return;
//int m=(l+r)>>1;
//print(idx*2+1,l,m);
//print(idx*2+2,m,r);
//}
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];
}
build(0,0,n);
//print(0,0,n);
return (seg[0].pre*seg[0].ymax).val;
}
int updateX(int pos, int val) {
x[pos]=val;
update(0,0,n,pos);
return (seg[0].pre*seg[0].ymax).val;
}
int updateY(int pos, int val) {
y[pos]=val;
update(0,0,n,pos);
return (seg[0].pre*seg[0].ymax).val;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:120:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (seg[0].pre*seg[0].ymax).val;
^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:126:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (seg[0].pre*seg[0].ymax).val;
^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:132:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (seg[0].pre*seg[0].ymax).val;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
141176 KB |
Output is correct |
2 |
Correct |
103 ms |
141280 KB |
Output is correct |
3 |
Correct |
103 ms |
141352 KB |
Output is correct |
4 |
Correct |
103 ms |
141460 KB |
Output is correct |
5 |
Correct |
103 ms |
141460 KB |
Output is correct |
6 |
Correct |
103 ms |
141460 KB |
Output is correct |
7 |
Correct |
101 ms |
141460 KB |
Output is correct |
8 |
Correct |
100 ms |
141460 KB |
Output is correct |
9 |
Correct |
104 ms |
141460 KB |
Output is correct |
10 |
Correct |
102 ms |
141460 KB |
Output is correct |
11 |
Correct |
110 ms |
141460 KB |
Output is correct |
12 |
Correct |
105 ms |
141468 KB |
Output is correct |
13 |
Correct |
100 ms |
141504 KB |
Output is correct |
14 |
Correct |
99 ms |
141504 KB |
Output is correct |
15 |
Correct |
98 ms |
141504 KB |
Output is correct |
16 |
Correct |
98 ms |
141548 KB |
Output is correct |
17 |
Correct |
100 ms |
141548 KB |
Output is correct |
18 |
Correct |
98 ms |
141548 KB |
Output is correct |
19 |
Correct |
104 ms |
141548 KB |
Output is correct |
20 |
Correct |
97 ms |
141548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
141676 KB |
Output is correct |
2 |
Correct |
99 ms |
141676 KB |
Output is correct |
3 |
Correct |
100 ms |
141676 KB |
Output is correct |
4 |
Correct |
100 ms |
141676 KB |
Output is correct |
5 |
Correct |
103 ms |
141676 KB |
Output is correct |
6 |
Correct |
101 ms |
141676 KB |
Output is correct |
7 |
Correct |
112 ms |
141676 KB |
Output is correct |
8 |
Correct |
111 ms |
141676 KB |
Output is correct |
9 |
Correct |
99 ms |
141676 KB |
Output is correct |
10 |
Correct |
121 ms |
141676 KB |
Output is correct |
11 |
Correct |
101 ms |
141676 KB |
Output is correct |
12 |
Correct |
110 ms |
141676 KB |
Output is correct |
13 |
Correct |
110 ms |
141676 KB |
Output is correct |
14 |
Correct |
99 ms |
141676 KB |
Output is correct |
15 |
Correct |
107 ms |
141676 KB |
Output is correct |
16 |
Correct |
100 ms |
141676 KB |
Output is correct |
17 |
Correct |
100 ms |
141676 KB |
Output is correct |
18 |
Correct |
100 ms |
141676 KB |
Output is correct |
19 |
Correct |
102 ms |
141676 KB |
Output is correct |
20 |
Correct |
99 ms |
141676 KB |
Output is correct |
21 |
Correct |
103 ms |
141676 KB |
Output is correct |
22 |
Correct |
99 ms |
141676 KB |
Output is correct |
23 |
Correct |
100 ms |
141676 KB |
Output is correct |
24 |
Correct |
99 ms |
141676 KB |
Output is correct |
25 |
Correct |
99 ms |
141676 KB |
Output is correct |
26 |
Correct |
109 ms |
141676 KB |
Output is correct |
27 |
Correct |
104 ms |
141676 KB |
Output is correct |
28 |
Correct |
102 ms |
141676 KB |
Output is correct |
29 |
Correct |
101 ms |
141676 KB |
Output is correct |
30 |
Correct |
104 ms |
141676 KB |
Output is correct |
31 |
Correct |
103 ms |
141676 KB |
Output is correct |
32 |
Correct |
102 ms |
141676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
146428 KB |
Output is correct |
2 |
Correct |
307 ms |
146508 KB |
Output is correct |
3 |
Correct |
275 ms |
146508 KB |
Output is correct |
4 |
Correct |
287 ms |
146508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
146508 KB |
Output is correct |
2 |
Correct |
100 ms |
146508 KB |
Output is correct |
3 |
Correct |
103 ms |
146508 KB |
Output is correct |
4 |
Correct |
100 ms |
146508 KB |
Output is correct |
5 |
Correct |
106 ms |
146508 KB |
Output is correct |
6 |
Correct |
103 ms |
146508 KB |
Output is correct |
7 |
Correct |
108 ms |
146508 KB |
Output is correct |
8 |
Correct |
102 ms |
146508 KB |
Output is correct |
9 |
Correct |
102 ms |
146508 KB |
Output is correct |
10 |
Correct |
102 ms |
146508 KB |
Output is correct |
11 |
Correct |
106 ms |
146508 KB |
Output is correct |
12 |
Correct |
103 ms |
146508 KB |
Output is correct |
13 |
Correct |
102 ms |
146508 KB |
Output is correct |
14 |
Correct |
99 ms |
146508 KB |
Output is correct |
15 |
Correct |
101 ms |
146508 KB |
Output is correct |
16 |
Correct |
100 ms |
146508 KB |
Output is correct |
17 |
Correct |
98 ms |
146508 KB |
Output is correct |
18 |
Correct |
99 ms |
146508 KB |
Output is correct |
19 |
Correct |
98 ms |
146508 KB |
Output is correct |
20 |
Correct |
103 ms |
146508 KB |
Output is correct |
21 |
Correct |
97 ms |
146508 KB |
Output is correct |
22 |
Correct |
102 ms |
146508 KB |
Output is correct |
23 |
Correct |
104 ms |
146508 KB |
Output is correct |
24 |
Correct |
118 ms |
146508 KB |
Output is correct |
25 |
Correct |
105 ms |
146508 KB |
Output is correct |
26 |
Correct |
103 ms |
146508 KB |
Output is correct |
27 |
Correct |
105 ms |
146508 KB |
Output is correct |
28 |
Correct |
103 ms |
146508 KB |
Output is correct |
29 |
Correct |
106 ms |
146508 KB |
Output is correct |
30 |
Correct |
102 ms |
146508 KB |
Output is correct |
31 |
Correct |
120 ms |
146508 KB |
Output is correct |
32 |
Correct |
102 ms |
146508 KB |
Output is correct |
33 |
Correct |
159 ms |
146508 KB |
Output is correct |
34 |
Correct |
158 ms |
146508 KB |
Output is correct |
35 |
Correct |
166 ms |
146508 KB |
Output is correct |
36 |
Correct |
172 ms |
146508 KB |
Output is correct |
37 |
Correct |
148 ms |
146508 KB |
Output is correct |
38 |
Correct |
145 ms |
146508 KB |
Output is correct |
39 |
Correct |
138 ms |
146508 KB |
Output is correct |
40 |
Correct |
149 ms |
146508 KB |
Output is correct |
41 |
Correct |
143 ms |
146508 KB |
Output is correct |
42 |
Correct |
137 ms |
146508 KB |
Output is correct |
43 |
Correct |
148 ms |
146508 KB |
Output is correct |
44 |
Correct |
146 ms |
146508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
146508 KB |
Output is correct |
2 |
Correct |
102 ms |
146508 KB |
Output is correct |
3 |
Correct |
98 ms |
146508 KB |
Output is correct |
4 |
Correct |
100 ms |
146508 KB |
Output is correct |
5 |
Correct |
98 ms |
146508 KB |
Output is correct |
6 |
Correct |
99 ms |
146508 KB |
Output is correct |
7 |
Correct |
101 ms |
146508 KB |
Output is correct |
8 |
Correct |
111 ms |
146508 KB |
Output is correct |
9 |
Correct |
97 ms |
146508 KB |
Output is correct |
10 |
Correct |
100 ms |
146508 KB |
Output is correct |
11 |
Correct |
107 ms |
146508 KB |
Output is correct |
12 |
Correct |
104 ms |
146508 KB |
Output is correct |
13 |
Correct |
98 ms |
146508 KB |
Output is correct |
14 |
Correct |
101 ms |
146508 KB |
Output is correct |
15 |
Correct |
98 ms |
146508 KB |
Output is correct |
16 |
Correct |
98 ms |
146508 KB |
Output is correct |
17 |
Correct |
99 ms |
146508 KB |
Output is correct |
18 |
Correct |
98 ms |
146508 KB |
Output is correct |
19 |
Correct |
106 ms |
146508 KB |
Output is correct |
20 |
Correct |
116 ms |
146508 KB |
Output is correct |
21 |
Correct |
101 ms |
146508 KB |
Output is correct |
22 |
Correct |
105 ms |
146508 KB |
Output is correct |
23 |
Correct |
99 ms |
146508 KB |
Output is correct |
24 |
Correct |
99 ms |
146508 KB |
Output is correct |
25 |
Correct |
104 ms |
146508 KB |
Output is correct |
26 |
Correct |
104 ms |
146508 KB |
Output is correct |
27 |
Correct |
103 ms |
146508 KB |
Output is correct |
28 |
Correct |
105 ms |
146508 KB |
Output is correct |
29 |
Correct |
106 ms |
146508 KB |
Output is correct |
30 |
Correct |
104 ms |
146508 KB |
Output is correct |
31 |
Correct |
107 ms |
146508 KB |
Output is correct |
32 |
Correct |
101 ms |
146508 KB |
Output is correct |
33 |
Correct |
192 ms |
146524 KB |
Output is correct |
34 |
Correct |
309 ms |
146524 KB |
Output is correct |
35 |
Correct |
279 ms |
146524 KB |
Output is correct |
36 |
Correct |
293 ms |
146524 KB |
Output is correct |
37 |
Correct |
153 ms |
146524 KB |
Output is correct |
38 |
Correct |
162 ms |
146524 KB |
Output is correct |
39 |
Correct |
166 ms |
146524 KB |
Output is correct |
40 |
Correct |
167 ms |
146524 KB |
Output is correct |
41 |
Correct |
142 ms |
146524 KB |
Output is correct |
42 |
Correct |
141 ms |
146524 KB |
Output is correct |
43 |
Correct |
131 ms |
146524 KB |
Output is correct |
44 |
Correct |
153 ms |
146524 KB |
Output is correct |
45 |
Correct |
135 ms |
146524 KB |
Output is correct |
46 |
Correct |
139 ms |
146524 KB |
Output is correct |
47 |
Correct |
157 ms |
146524 KB |
Output is correct |
48 |
Correct |
149 ms |
146524 KB |
Output is correct |
49 |
Correct |
287 ms |
146536 KB |
Output is correct |
50 |
Correct |
295 ms |
146536 KB |
Output is correct |
51 |
Correct |
211 ms |
146536 KB |
Output is correct |
52 |
Correct |
214 ms |
146536 KB |
Output is correct |
53 |
Correct |
294 ms |
146536 KB |
Output is correct |
54 |
Correct |
203 ms |
146536 KB |
Output is correct |
55 |
Correct |
192 ms |
146536 KB |
Output is correct |
56 |
Correct |
208 ms |
146536 KB |
Output is correct |
57 |
Correct |
189 ms |
146536 KB |
Output is correct |
58 |
Correct |
199 ms |
146536 KB |
Output is correct |
59 |
Correct |
146 ms |
146536 KB |
Output is correct |