# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
524133 |
2022-02-08T17:00:15 Z |
Lobo |
Horses (IOI15_horses) |
C++17 |
|
1438 ms |
73240 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 550000
int n, a[maxn], b[maxn], trmx[4*maxn], trp[4*maxn];
map<int,pair<int,int>> lr;
int mod = 1e9 + 7;
dbl logmax, logtot;
void attmx(int no, int l, int r, int pos, int val) {
if(l > pos || r < pos) return;
else if(l == r) trmx[no] = val;
else {
int f1 = 2*no;
int f2 = 2*no + 1;
int mid = (l+r)>>1;
attmx(f1,l,mid,pos,val);
attmx(f2,mid+1,r,pos,val);
trmx[no] = max(trmx[f1],trmx[f2]);
}
}
int qrmx(int no, int l, int r, int L, int R) {
if(l > R || r < L) return 0;
else if(l >= L && r <= R) return trmx[no];
else {
int f1 = 2*no;
int f2 = 2*no + 1;
int mid = (l+r)>>1;
return max(qrmx(f1,l,mid,L,R),qrmx(f2,mid+1,r,L,R));
}
}
void attp(int no, int l, int r, int pos, int val) {
if(l > pos || r < pos) return;
else if(l == r) trp[no] = val;
else {
int f1 = 2*no;
int f2 = 2*no + 1;
int mid = (l+r)>>1;
attp(f1,l,mid,pos,val);
attp(f2,mid+1,r,pos,val);
trp[no] = (trp[f1]*trp[f2])%mod;
}
}
int qrp(int no, int l, int r, int L, int R) {
if(l > R || r < L) return 1;
else if(l >= L && r <= R) return trp[no];
else {
int f1 = 2*no;
int f2 = 2*no + 1;
int mid = (l+r)>>1;
return (qrp(f1,l,mid,L,R)*qrp(f2,mid+1,r,L,R))%mod;
}
}
int qrr() {
auto it = lr.end(); it--;
dbl logcur = logtot;
int ans = 0;
dbl anslg = -inf;
while(true) {
int l = it->fr;
int r = it->sc.fr;
int p = it->sc.sc;
int mx = qrmx(1,0,n-1,l,r);
dbl anscur = log2(mx) + logcur;
if(anscur >= anslg) {
anslg = anscur;
ans = (qrp(1,0,n-1,0,r)*mx)%mod;
}
logcur -= log2(p);
if(logcur + logmax < logtot || it == lr.begin()) break;
it--;
}
return ans;
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
n = N;
logtot = 0;
logmax = 31;
for(int i = 0; i < n; i++) {
a[i] = X[i];
logtot+= log2(a[i]);
attp(1,0,n-1,i,a[i]);
}
for(int i = 0; i < n; i++) {
b[i] = Y[i];
attmx(1,0,n-1,i,b[i]);
}
for(int i = 0; i < n;) {
if(a[i] != 1) {
lr[i] = mp(i,a[i]);
i++;
}
else {
int ant = i;
while(i < n && a[i] == 1) {
i++;
}
lr[ant] = mp(i-1,1);
}
}
return qrr();
}
int32_t updateX(int32_t pos, int32_t val) {
if(val == a[pos]) {
return qrr();
}
attp(1,0,n-1,pos,val);
logtot-= log2(a[pos]);
logtot+= log2(val);
if(a[pos] != 1 && val != 1) {
a[pos] = val;
lr[pos] = mp(pos,val);
return qrr();
}
auto it = lr.upper_bound(pos); it--;
if(val == 1) {
//quero pegar o cara da direita e da esquerda e juntar com esse
vector<int> tir;
int l = pos;
int r = pos;
if(it != lr.begin()) {
it--;
//tiro ele se for igual a 1
if(it->sc.sc == 1) {
l = it->fr;
tir.pb(it->fr);
}
it++;
}
it++;
if(it != lr.end()) {
if(it->sc.sc == 1) {
r = it->sc.fr;
tir.pb(it->fr);
}
}
it--;
tir.pb(it->fr);
for(auto x : tir) {
lr.erase(x);
}
lr[l] = mp(r,1);
}
else {
//quero pegar o cara da direita e da esquerda e separar
int l = it->fr;
int r = it->sc.fr;
lr.erase(l);
if(l != pos) {
//inserir (l,pos-1)
lr[l] = mp(pos-1,1);
}
lr[pos] = mp(pos,val);
if(r != pos) {
lr[pos+1] = mp(r,1);
}
}
a[pos] = val;
return qrr();
}
int32_t updateY(int32_t pos, int32_t val) {
b[pos] = val;
attmx(1,0,n-1,pos,val);
return qrr();
}
Compilation message
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:130:15: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
130 | return qrr();
| ~~~^~
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:135:19: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
135 | return qrr();
| ~~~^~
horses.cpp:145:19: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
145 | return qrr();
| ~~~^~
horses.cpp:198:15: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
198 | return qrr();
| ~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:205:15: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
205 | return qrr();
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
288 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
308 KB |
Output is correct |
24 |
Correct |
2 ms |
292 KB |
Output is correct |
25 |
Correct |
2 ms |
444 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
6 ms |
316 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
440 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
898 ms |
61996 KB |
Output is correct |
2 |
Correct |
561 ms |
62020 KB |
Output is correct |
3 |
Correct |
521 ms |
62060 KB |
Output is correct |
4 |
Correct |
648 ms |
68348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
280 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
284 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
3 ms |
432 KB |
Output is correct |
26 |
Correct |
2 ms |
436 KB |
Output is correct |
27 |
Correct |
6 ms |
312 KB |
Output is correct |
28 |
Correct |
4 ms |
436 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
332 KB |
Output is correct |
32 |
Correct |
7 ms |
332 KB |
Output is correct |
33 |
Correct |
236 ms |
32808 KB |
Output is correct |
34 |
Correct |
236 ms |
32756 KB |
Output is correct |
35 |
Correct |
422 ms |
70720 KB |
Output is correct |
36 |
Correct |
365 ms |
70708 KB |
Output is correct |
37 |
Correct |
348 ms |
30860 KB |
Output is correct |
38 |
Correct |
366 ms |
62988 KB |
Output is correct |
39 |
Correct |
224 ms |
30456 KB |
Output is correct |
40 |
Correct |
371 ms |
65944 KB |
Output is correct |
41 |
Correct |
253 ms |
30588 KB |
Output is correct |
42 |
Correct |
319 ms |
30716 KB |
Output is correct |
43 |
Correct |
351 ms |
66116 KB |
Output is correct |
44 |
Correct |
367 ms |
66140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
424 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
440 KB |
Output is correct |
27 |
Correct |
6 ms |
332 KB |
Output is correct |
28 |
Correct |
5 ms |
568 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
3 ms |
332 KB |
Output is correct |
32 |
Correct |
8 ms |
316 KB |
Output is correct |
33 |
Correct |
895 ms |
64616 KB |
Output is correct |
34 |
Correct |
560 ms |
73240 KB |
Output is correct |
35 |
Correct |
559 ms |
64448 KB |
Output is correct |
36 |
Correct |
693 ms |
68316 KB |
Output is correct |
37 |
Correct |
236 ms |
32928 KB |
Output is correct |
38 |
Correct |
235 ms |
32772 KB |
Output is correct |
39 |
Correct |
436 ms |
70688 KB |
Output is correct |
40 |
Correct |
399 ms |
70672 KB |
Output is correct |
41 |
Correct |
341 ms |
30908 KB |
Output is correct |
42 |
Correct |
400 ms |
62844 KB |
Output is correct |
43 |
Correct |
224 ms |
30532 KB |
Output is correct |
44 |
Correct |
401 ms |
65968 KB |
Output is correct |
45 |
Correct |
247 ms |
30596 KB |
Output is correct |
46 |
Correct |
317 ms |
30676 KB |
Output is correct |
47 |
Correct |
389 ms |
66160 KB |
Output is correct |
48 |
Correct |
399 ms |
66044 KB |
Output is correct |
49 |
Correct |
402 ms |
37396 KB |
Output is correct |
50 |
Correct |
330 ms |
37284 KB |
Output is correct |
51 |
Correct |
635 ms |
72596 KB |
Output is correct |
52 |
Correct |
470 ms |
72200 KB |
Output is correct |
53 |
Correct |
1438 ms |
35500 KB |
Output is correct |
54 |
Correct |
720 ms |
64776 KB |
Output is correct |
55 |
Correct |
373 ms |
31540 KB |
Output is correct |
56 |
Correct |
548 ms |
67664 KB |
Output is correct |
57 |
Correct |
607 ms |
32240 KB |
Output is correct |
58 |
Correct |
1262 ms |
32836 KB |
Output is correct |
59 |
Correct |
376 ms |
66124 KB |
Output is correct |