Submission #395789

# Submission time Handle Problem Language Result Execution time Memory
395789 2021-04-28T23:06:03 Z peuch Horses (IOI15_horses) C++17
100 / 100
1084 ms 50244 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;

const long long MAXN = 5e5 + 10;
const long long MOD = 1e9 + 7;

long long n;
long long x[MAXN], y[MAXN];

long long segX[4 * MAXN], segY[4 * MAXN], segV[4 * MAXN];

long long merge(long long pos, long long e, long long d);
void buildY(long long pos, long long ini, long long fim);
void buildX(long long pos, long long ini, long long fim);
void buildV(long long pos, long long ini, long long fim);
long long queryX(long long pos, long long ini, long long fim, long long p, long long q);
long long queryV(long long pos, long long ini, long long fim, long long p, long long q);
void upY(long long pos, long long ini, long long fim, long long id);
void upX(long long pos, long long ini, long long fim, long long id);
void upV(long long pos, long long ini, long long fim, long long id);

int init(int N, int X[], int Y[]) {
	n = N;
	for(long long i = 1; i <= n; i++)
		x[i] = X[i - 1], y[i] = Y[i - 1];
	buildX(1, 1, n);
	buildV(1, 1, n);
	buildY(1, 1, n);
	return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
}

long long merge(long long e, long long d){
	long long aux = queryX(1, 1, n, e + 1, d);
	if(aux * y[d] >= y[e]) return d;
	else return e;
}

void buildY(long long pos, long long ini, long long fim){
	if(ini == fim){
		segY[pos] = ini;
		return;
	}
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	buildY(e, ini, mid);
	buildY(d, mid + 1, fim);
	segY[pos] = merge(segY[e], segY[d]);
}

void buildX(long long pos, long long ini, long long fim){
	if(ini == fim){
		segX[pos] = x[ini];
		return;
	}
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	buildX(e, ini, mid);
	buildX(d, mid + 1, fim);
	segX[pos] = min(MOD + 1, segX[e] * segX[d]);
}

void buildV(long long pos, long long ini, long long fim){
	if(ini == fim){
		segV[pos] = x[ini];
		return;
	}
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	buildV(e, ini, mid);
	buildV(d, mid + 1, fim);
	segV[pos] = (segV[e] * segV[d]) % MOD;
}

long long queryX(long long pos, long long ini, long long fim, long long p, long long q){
	if(ini > q || fim < p) return 1;
	if(ini >= p && fim <= q) return segX[pos];
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	return min(queryX(e, ini, mid, p, q) * queryX(d, mid + 1, fim, p, q), MOD + 1);
}

long long queryV(long long pos, long long ini, long long fim, long long p, long long q){
	if(ini > q || fim < p) return 1;
	if(ini >= p && fim <= q) return segV[pos];
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	return (queryV(e, ini, mid, p, q) * queryV(d, mid + 1, fim, p, q)) % MOD;
}

void upY(long long pos, long long ini, long long fim, long long id){
	if(ini > id || fim < id) return;
	if(ini == fim) return;
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	upY(e, ini, mid, id);
	upY(d, mid + 1, fim, id);
	segY[pos] = merge(segY[e], segY[d]);
}

void upX(long long pos, long long ini, long long fim, long long id){
	if(ini > id || fim < id) return;
	if(ini == fim) {segX[pos] = x[id]; return;}
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	upX(e, ini, mid, id);
	upX(d, mid + 1, fim, id);
	segX[pos] = min(MOD + 1, segX[e] * segX[d]);
}

void upV(long long pos, long long ini, long long fim, long long id){
	if(ini > id || fim < id) return;
	if(ini == fim) {segV[pos] = x[id]; return;}
	long long mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
	upV(e, ini, mid, id);
	upV(d, mid + 1, fim, id);
	segV[pos] = (segV[e] * segV[d]) % MOD;
}

int updateY(int pos, int val){
	pos++;
	y[pos] = val;
	upX(1, 1, n, pos);
	upV(1, 1, n, pos);
	upY(1, 1, n, pos);
	return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
}

int updateX(int pos, int val){
	pos++;
	x[pos] = val;
	upX(1, 1, n, pos);
	upV(1, 1, n, pos);
	upY(1, 1, n, pos);
	return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:30:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   30 |  return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:119:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |  return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:128:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  128 |  return (y[segY[1]] * queryV(1, 1, n, 1, segY[1])) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 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 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 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 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 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
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 2 ms 320 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 636 ms 37696 KB Output is correct
2 Correct 626 ms 37888 KB Output is correct
3 Correct 768 ms 37660 KB Output is correct
4 Correct 732 ms 37776 KB Output is correct
# 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 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 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
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 3 ms 320 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 320 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 264 ms 40624 KB Output is correct
34 Correct 253 ms 40704 KB Output is correct
35 Correct 240 ms 47684 KB Output is correct
36 Correct 212 ms 47476 KB Output is correct
37 Correct 212 ms 38848 KB Output is correct
38 Correct 211 ms 39912 KB Output is correct
39 Correct 177 ms 38724 KB Output is correct
40 Correct 195 ms 42688 KB Output is correct
41 Correct 194 ms 38736 KB Output is correct
42 Correct 191 ms 38852 KB Output is correct
43 Correct 174 ms 43064 KB Output is correct
44 Correct 169 ms 42972 KB Output is correct
# 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 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 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
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 633 ms 41444 KB Output is correct
34 Correct 622 ms 50244 KB Output is correct
35 Correct 767 ms 41368 KB Output is correct
36 Correct 739 ms 45312 KB Output is correct
37 Correct 264 ms 40628 KB Output is correct
38 Correct 257 ms 40708 KB Output is correct
39 Correct 243 ms 47600 KB Output is correct
40 Correct 213 ms 47540 KB Output is correct
41 Correct 219 ms 38852 KB Output is correct
42 Correct 210 ms 39756 KB Output is correct
43 Correct 184 ms 38708 KB Output is correct
44 Correct 199 ms 42684 KB Output is correct
45 Correct 200 ms 38796 KB Output is correct
46 Correct 194 ms 38912 KB Output is correct
47 Correct 176 ms 42952 KB Output is correct
48 Correct 174 ms 43120 KB Output is correct
49 Correct 1084 ms 42820 KB Output is correct
50 Correct 1014 ms 42720 KB Output is correct
51 Correct 692 ms 49440 KB Output is correct
52 Correct 452 ms 49100 KB Output is correct
53 Correct 838 ms 41028 KB Output is correct
54 Correct 634 ms 41652 KB Output is correct
55 Correct 453 ms 39872 KB Output is correct
56 Correct 483 ms 44484 KB Output is correct
57 Correct 596 ms 40388 KB Output is correct
58 Correct 575 ms 40900 KB Output is correct
59 Correct 174 ms 43068 KB Output is correct