Submission #893714

# Submission time Handle Problem Language Result Execution time Memory
893714 2023-12-27T10:10:42 Z yellowtoad Horses (IOI15_horses) C++17
17 / 100
996 ms 39472 KB
#include "horses.h"
#include <iostream>
#define int long long
using namespace std;

const long long mod = 1e9+7;
long long n, a[500010], b[500010], node[2000010][3];
bool done;

/*
0: x product
1: max x
2: max y
*/

void build(int id, int x, int y) {
	if (x == y) {
		node[id][0] = a[x]%mod;
		node[id][1] = a[x];
		node[id][2] = b[x];
		return;
	}
	int mid = (x+y)/2;
	build(id*2,x,mid);
	build(id*2+1,mid+1,y);
	node[id][0] = (node[id*2][0]*node[id*2+1][0])%mod;
	node[id][1] = max(node[id*2][1],node[id*2+1][1]);
	node[id][2] = max(node[id*2][2],node[id*2+1][2]);
}

void update(int id, int jd, int x, int y, int pos, int val) {
	if (x == y) {
		node[id][jd] = val;
		return;
	}
	int mid = (x+y)/2;
	if (pos <= mid) update(id*2,jd,x,mid,pos,val);
	else update(id*2+1,jd,mid+1,y,pos,val);
	if (jd == 0) node[id][0] = (node[id*2][0]*node[id*2+1][0])%mod;
	else if (jd == 1) node[id][1] = max(node[id*2][1],node[id*2+1][1]);
	else node[id][2] = max(node[id*2][2],node[id*2+1][2]);
}

int nxt(int id, int x, int y, int r) {
	if (x > r) return 0;
	if (node[id][1] == 1) return 0;
	if (x == y) {
		done = 1;
		return x;
	}
	int mid = (x+y)/2, tmp = nxt(id*2+1,mid+1,y,r);
	if (!done) return nxt(id*2,x,mid,r);
	else return tmp;
}

long long find_max(int id, int x, int y, int l, int r) {
	if ((l <= x) && (y <= r)) return node[id][2];
	if ((y < l) || (r < x)) return 0;
	int mid = (x+y)/2;
	return max(find_max(id*2,x,mid,l,r),find_max(id*2+1,mid+1,y,l,r));
}

long long find_pro(int id, int x, int y, int l, int r) {
	if ((l <= x) && (y <= r)) return node[id][0];
	if ((y < l) || (r < x)) return 1;
	int mid = (x+y)/2;
	return (find_pro(id*2,x,mid,l,r)*find_pro(id*2+1,mid+1,y,l,r))%mod;
}

long long solve() {
	long long cur = nxt(1,1,n,n)-1, lst = n, maxx = 1;
	while (maxx <= 1e9+7) {
		maxx = max(maxx,find_max(1,1,n,cur+1,lst));
		lst = cur+1;
		maxx *= find_pro(1,1,n,lst,lst);
		done = 0;
		if (cur == -1) break;
		cur = nxt(1,1,n,cur)-1;
	}
	return ((maxx%mod)*find_pro(1,1,n,1,cur))%mod;
}

signed init(signed N, signed X[], signed Y[]) {
	n = N;
	for (int i = 0; i < n; i++) a[i+1] = X[i], b[i+1] = Y[i];
	build(1,1,n);
	return solve();
}

signed updateX(signed pos, signed val) {
	pos++;
	update(1,0,1,n,pos,val%mod);
	update(1,1,1,n,pos,val);
	return solve();
}

signed updateY(signed pos, signed val) {
	pos++;
	update(1,2,1,n,pos,val);
	return solve();
}

Compilation message

horses.cpp: In function 'long long int solve()':
horses.cpp:72:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   72 |  while (maxx <= 1e9+7) {
      |         ^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:87:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   94 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:100:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  100 |  return solve();
      |         ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4544 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4448 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Incorrect 1 ms 4552 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 996 ms 39472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4536 KB Output is correct
4 Correct 0 ms 4600 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Incorrect 1 ms 4440 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4524 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Incorrect 1 ms 4444 KB Output isn't correct
22 Halted 0 ms 0 KB -