# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
399521 |
2021-05-05T23:56:20 Z |
bigg |
Horses (IOI15_horses) |
C++14 |
|
590 ms |
106052 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 10;
const ll MOD = 1e9 + 7;
#define esq(x) x << 1
#define dir(x) (x<<1) | 1
#define mid(x,y,t) ((x+y)>>1) + t
ll Y[MAXN], X[MAXN];
int n;
struct nodeseg
{
ll v, id, xm;
bool flag;
nodeseg(ll _v = 0, ll _id = 0, ll _xm = 0, bool f = 0){
v = _v;
id = _id;
xm = _xm;
flag = f;
}
nodeseg operator + (nodeseg b){
if(flag && b.flag) return nodeseg(0,0,0,1);
if(flag) return b;
if(b.flag) return *this;
nodeseg ans;
if(v >= b.v){
ans.id = id;
ans.v = v;
}else{
ans.id = b.id;
ans.v = b.v;
}
ans.xm = (xm * b.xm)%MOD;
return ans;
}
}seg[4*MAXN];
void build(int node, int x, int y){
if(x == y){
seg[node] = nodeseg(Y[x], x, X[x], 0);
return;
}
build(esq(node), x, mid(x,y,0));
build(dir(node), mid(x,y,1), y);
seg[node] = seg[esq(node)] + seg[dir(node)];
}
void update(int node, int x, int y, int id, int t){
if(x > id || y < id ) return;
if(x == y){
seg[node].v = Y[x];
seg[node].xm = X[x];
return;
}
if(id <= mid(x,y,0)) update(esq(node), x, mid(x,y,0), id, t);
else update(dir(node), mid(x,y,1), y, id, t);
seg[node] = seg[esq(node)] + seg[dir(node)];
}
nodeseg query(int node, int x, int y, int l, int r){
if(x > r || y < l || y < x || r < l) return nodeseg(0,-1,1,0);
if(x >= l && y <= r) return seg[node];
if(r <= mid(x,y,0)) return query(esq(node), x, mid(x,y,0), l, r);
else if(l > mid(x,y,0)) return query(dir(node), mid(x,y,1), y, l, r);
nodeseg e = query(esq(node), x, mid(x,y,0), l, r);
nodeseg d = query(dir(node), mid(x,y,1), y, l, r);
return e + d;
}
set<int> ids;
ll makeans(){
if(ids.empty()) return (query(1,1,n,1,n).v)%MOD;
set<int> :: iterator it = ids.end();
it--;
ll ans = 0, id = 0;
int r = n;
while(true){
//printf("%d %d\n", r, *it);
nodeseg q = query(1,1,n,*it,r);
if(q.v >= ans) ans = q.v, id = q.id;
ans *= X[*it];
r = *it -1;
//printf("%d %d\n", r, *it);
if(it == ids.begin()) break;
if(ans > (ll) 1e9) break;
it--;
}
//printf("%d\n", r);
nodeseg q = query(1,1,n,1,r);
if(q.v >= ans) ans = q.v, id = q.id;
return (query(1,1,n,1,id).xm*Y[id])%MOD;
}
int init(int N, int x[], int y[]) {
n = N;
for(int i = 0; i < N; i++){
X[i+1] = x[i];
Y[i+1] = y[i];
}
build(1,1,n);
for(int i = 1; i <= n; i++) if(X[i] >= 2) ids.insert(i);
return makeans();
}
int updateX(int pos, int val) {
pos++;
if(X[pos] >= 2)ids.erase(pos);
X[pos] = val;
if(X[pos] >= 2) ids.insert(pos);
update(1,1,n,pos,1);
return makeans();
}
int updateY(int pos, int val) {
pos++;
Y[pos] = val;
update(1,1,n,pos,0);
return makeans();
}
Compilation message
horses.cpp: In function 'll makeans()':
horses.cpp:103:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
103 | return (query(1,1,n,1,id).xm*Y[id])%MOD;
| ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:116:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
116 | return makeans();
| ~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:126:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
126 | return makeans();
| ~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:133:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
133 | return makeans();
| ~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
62924 KB |
Output is correct |
2 |
Correct |
29 ms |
62828 KB |
Output is correct |
3 |
Correct |
28 ms |
62916 KB |
Output is correct |
4 |
Correct |
30 ms |
62916 KB |
Output is correct |
5 |
Correct |
28 ms |
62948 KB |
Output is correct |
6 |
Correct |
29 ms |
62868 KB |
Output is correct |
7 |
Correct |
28 ms |
62940 KB |
Output is correct |
8 |
Correct |
28 ms |
62892 KB |
Output is correct |
9 |
Correct |
28 ms |
62916 KB |
Output is correct |
10 |
Correct |
29 ms |
62908 KB |
Output is correct |
11 |
Correct |
29 ms |
62920 KB |
Output is correct |
12 |
Correct |
28 ms |
62852 KB |
Output is correct |
13 |
Correct |
28 ms |
62920 KB |
Output is correct |
14 |
Correct |
33 ms |
62920 KB |
Output is correct |
15 |
Correct |
33 ms |
62944 KB |
Output is correct |
16 |
Correct |
28 ms |
62964 KB |
Output is correct |
17 |
Correct |
28 ms |
62916 KB |
Output is correct |
18 |
Correct |
28 ms |
62908 KB |
Output is correct |
19 |
Correct |
28 ms |
62880 KB |
Output is correct |
20 |
Correct |
28 ms |
62924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62856 KB |
Output is correct |
2 |
Correct |
33 ms |
62844 KB |
Output is correct |
3 |
Correct |
30 ms |
62892 KB |
Output is correct |
4 |
Correct |
28 ms |
62916 KB |
Output is correct |
5 |
Correct |
29 ms |
62872 KB |
Output is correct |
6 |
Correct |
28 ms |
62868 KB |
Output is correct |
7 |
Correct |
28 ms |
62924 KB |
Output is correct |
8 |
Correct |
28 ms |
62928 KB |
Output is correct |
9 |
Correct |
29 ms |
62916 KB |
Output is correct |
10 |
Correct |
29 ms |
62892 KB |
Output is correct |
11 |
Correct |
29 ms |
62824 KB |
Output is correct |
12 |
Correct |
28 ms |
62868 KB |
Output is correct |
13 |
Correct |
28 ms |
62924 KB |
Output is correct |
14 |
Correct |
28 ms |
62816 KB |
Output is correct |
15 |
Correct |
29 ms |
62896 KB |
Output is correct |
16 |
Correct |
28 ms |
62924 KB |
Output is correct |
17 |
Correct |
29 ms |
62872 KB |
Output is correct |
18 |
Correct |
30 ms |
62920 KB |
Output is correct |
19 |
Correct |
33 ms |
62916 KB |
Output is correct |
20 |
Correct |
28 ms |
62928 KB |
Output is correct |
21 |
Correct |
29 ms |
62808 KB |
Output is correct |
22 |
Correct |
28 ms |
62908 KB |
Output is correct |
23 |
Correct |
28 ms |
62932 KB |
Output is correct |
24 |
Correct |
29 ms |
62876 KB |
Output is correct |
25 |
Correct |
29 ms |
62916 KB |
Output is correct |
26 |
Correct |
29 ms |
62920 KB |
Output is correct |
27 |
Correct |
31 ms |
62916 KB |
Output is correct |
28 |
Correct |
29 ms |
62896 KB |
Output is correct |
29 |
Correct |
30 ms |
62824 KB |
Output is correct |
30 |
Correct |
30 ms |
62956 KB |
Output is correct |
31 |
Correct |
29 ms |
62924 KB |
Output is correct |
32 |
Correct |
31 ms |
62924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
479 ms |
99192 KB |
Output is correct |
2 |
Correct |
387 ms |
99140 KB |
Output is correct |
3 |
Correct |
400 ms |
99032 KB |
Output is correct |
4 |
Correct |
441 ms |
99012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
62872 KB |
Output is correct |
2 |
Correct |
29 ms |
62828 KB |
Output is correct |
3 |
Correct |
28 ms |
62892 KB |
Output is correct |
4 |
Correct |
28 ms |
62924 KB |
Output is correct |
5 |
Correct |
29 ms |
62876 KB |
Output is correct |
6 |
Correct |
29 ms |
62924 KB |
Output is correct |
7 |
Correct |
29 ms |
62916 KB |
Output is correct |
8 |
Correct |
28 ms |
62856 KB |
Output is correct |
9 |
Correct |
29 ms |
62924 KB |
Output is correct |
10 |
Correct |
28 ms |
62944 KB |
Output is correct |
11 |
Correct |
28 ms |
62924 KB |
Output is correct |
12 |
Correct |
29 ms |
62888 KB |
Output is correct |
13 |
Correct |
28 ms |
62904 KB |
Output is correct |
14 |
Correct |
28 ms |
62848 KB |
Output is correct |
15 |
Correct |
28 ms |
62832 KB |
Output is correct |
16 |
Correct |
28 ms |
62800 KB |
Output is correct |
17 |
Correct |
28 ms |
62924 KB |
Output is correct |
18 |
Correct |
29 ms |
62800 KB |
Output is correct |
19 |
Correct |
30 ms |
62884 KB |
Output is correct |
20 |
Correct |
29 ms |
62844 KB |
Output is correct |
21 |
Correct |
28 ms |
62940 KB |
Output is correct |
22 |
Correct |
28 ms |
62864 KB |
Output is correct |
23 |
Correct |
29 ms |
62916 KB |
Output is correct |
24 |
Correct |
29 ms |
62960 KB |
Output is correct |
25 |
Correct |
29 ms |
62924 KB |
Output is correct |
26 |
Correct |
29 ms |
63008 KB |
Output is correct |
27 |
Correct |
31 ms |
62920 KB |
Output is correct |
28 |
Correct |
29 ms |
62900 KB |
Output is correct |
29 |
Correct |
29 ms |
62924 KB |
Output is correct |
30 |
Correct |
29 ms |
62880 KB |
Output is correct |
31 |
Correct |
29 ms |
62948 KB |
Output is correct |
32 |
Correct |
35 ms |
62868 KB |
Output is correct |
33 |
Correct |
86 ms |
74800 KB |
Output is correct |
34 |
Correct |
76 ms |
74820 KB |
Output is correct |
35 |
Correct |
212 ms |
98188 KB |
Output is correct |
36 |
Correct |
205 ms |
98184 KB |
Output is correct |
37 |
Correct |
125 ms |
74820 KB |
Output is correct |
38 |
Correct |
140 ms |
86728 KB |
Output is correct |
39 |
Correct |
65 ms |
74620 KB |
Output is correct |
40 |
Correct |
195 ms |
98192 KB |
Output is correct |
41 |
Correct |
75 ms |
74728 KB |
Output is correct |
42 |
Correct |
86 ms |
74668 KB |
Output is correct |
43 |
Correct |
177 ms |
98140 KB |
Output is correct |
44 |
Correct |
180 ms |
98204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
62924 KB |
Output is correct |
2 |
Correct |
29 ms |
62924 KB |
Output is correct |
3 |
Correct |
33 ms |
62844 KB |
Output is correct |
4 |
Correct |
29 ms |
62908 KB |
Output is correct |
5 |
Correct |
28 ms |
62840 KB |
Output is correct |
6 |
Correct |
28 ms |
62884 KB |
Output is correct |
7 |
Correct |
28 ms |
62924 KB |
Output is correct |
8 |
Correct |
28 ms |
62924 KB |
Output is correct |
9 |
Correct |
28 ms |
62896 KB |
Output is correct |
10 |
Correct |
28 ms |
62892 KB |
Output is correct |
11 |
Correct |
28 ms |
62888 KB |
Output is correct |
12 |
Correct |
28 ms |
62924 KB |
Output is correct |
13 |
Correct |
28 ms |
62884 KB |
Output is correct |
14 |
Correct |
28 ms |
62904 KB |
Output is correct |
15 |
Correct |
28 ms |
62924 KB |
Output is correct |
16 |
Correct |
29 ms |
62924 KB |
Output is correct |
17 |
Correct |
32 ms |
62892 KB |
Output is correct |
18 |
Correct |
31 ms |
62924 KB |
Output is correct |
19 |
Correct |
30 ms |
62908 KB |
Output is correct |
20 |
Correct |
28 ms |
62924 KB |
Output is correct |
21 |
Correct |
29 ms |
62856 KB |
Output is correct |
22 |
Correct |
29 ms |
62900 KB |
Output is correct |
23 |
Correct |
29 ms |
62880 KB |
Output is correct |
24 |
Correct |
30 ms |
62924 KB |
Output is correct |
25 |
Correct |
30 ms |
62920 KB |
Output is correct |
26 |
Correct |
29 ms |
63008 KB |
Output is correct |
27 |
Correct |
31 ms |
62892 KB |
Output is correct |
28 |
Correct |
29 ms |
62996 KB |
Output is correct |
29 |
Correct |
29 ms |
62816 KB |
Output is correct |
30 |
Correct |
30 ms |
62960 KB |
Output is correct |
31 |
Correct |
30 ms |
62972 KB |
Output is correct |
32 |
Correct |
30 ms |
62908 KB |
Output is correct |
33 |
Correct |
478 ms |
99032 KB |
Output is correct |
34 |
Correct |
395 ms |
99336 KB |
Output is correct |
35 |
Correct |
395 ms |
99140 KB |
Output is correct |
36 |
Correct |
461 ms |
99092 KB |
Output is correct |
37 |
Correct |
79 ms |
74820 KB |
Output is correct |
38 |
Correct |
77 ms |
74784 KB |
Output is correct |
39 |
Correct |
213 ms |
98256 KB |
Output is correct |
40 |
Correct |
203 ms |
98188 KB |
Output is correct |
41 |
Correct |
119 ms |
74808 KB |
Output is correct |
42 |
Correct |
126 ms |
86724 KB |
Output is correct |
43 |
Correct |
66 ms |
74668 KB |
Output is correct |
44 |
Correct |
190 ms |
98224 KB |
Output is correct |
45 |
Correct |
76 ms |
74700 KB |
Output is correct |
46 |
Correct |
86 ms |
74660 KB |
Output is correct |
47 |
Correct |
187 ms |
98244 KB |
Output is correct |
48 |
Correct |
180 ms |
98104 KB |
Output is correct |
49 |
Correct |
237 ms |
76780 KB |
Output is correct |
50 |
Correct |
209 ms |
76740 KB |
Output is correct |
51 |
Correct |
366 ms |
99144 KB |
Output is correct |
52 |
Correct |
290 ms |
99132 KB |
Output is correct |
53 |
Correct |
590 ms |
76716 KB |
Output is correct |
54 |
Correct |
297 ms |
93620 KB |
Output is correct |
55 |
Correct |
191 ms |
77744 KB |
Output is correct |
56 |
Correct |
350 ms |
106052 KB |
Output is correct |
57 |
Correct |
289 ms |
78404 KB |
Output is correct |
58 |
Correct |
404 ms |
79044 KB |
Output is correct |
59 |
Correct |
180 ms |
104508 KB |
Output is correct |