Submission #590860

# Submission time Handle Problem Language Result Execution time Memory
590860 2022-07-06T12:26:59 Z yutabi Horses (IOI15_horses) C++14
100 / 100
133 ms 34252 KB
#include "horses.h"


#include <bits/stdc++.h>
using namespace std;


#define MOD 1000000007


typedef long long ll;





ll seg_tree_left_val[2000007];
bool seg_tree_left_big[2000007];

ll seg_tree_right_val[2000007];
bool seg_tree_right_big[2000007];

ll seg_tree_sell_price[2000007];


int n;

int* x;
int* y;


void merge(int node)
{
	ll res=seg_tree_right_val[node*2]*seg_tree_left_val[node*2+1];

	if(res>=MOD || seg_tree_right_big[node*2] || seg_tree_left_big[node*2+1] || (ll)(seg_tree_sell_price[node*2])<=res*(ll)(seg_tree_sell_price[node*2+1]))
	{
		seg_tree_right_val[node]=seg_tree_right_val[node*2+1];
		seg_tree_right_big[node]=seg_tree_right_big[node*2+1];
		seg_tree_sell_price[node]=seg_tree_sell_price[node*2+1];
		
		seg_tree_left_big[node]=0;

		if(res>=MOD)
		{
			seg_tree_left_big[node]=1;
			res%=MOD;
		}

		res*=seg_tree_left_val[node*2];
		
		if(res>=MOD)
		{
			seg_tree_left_big[node]=1;
			res%=MOD;
		}

		seg_tree_left_val[node]=res;

		if(seg_tree_left_big[node*2] || seg_tree_right_big[node*2] || seg_tree_left_big[node*2+1])
		{
			seg_tree_left_big[node]=1;
		}
	}

	else
	{
		seg_tree_left_val[node]=seg_tree_left_val[node*2];
		seg_tree_left_big[node]=seg_tree_left_big[node*2];
		seg_tree_sell_price[node]=seg_tree_sell_price[node*2];
		
		seg_tree_right_big[node]=0;

		if(res>=MOD)
		{
			seg_tree_right_big[node]=1;
			res%=MOD;
		}

		res*=seg_tree_right_val[node*2+1];
		
		if(res>=MOD)
		{
			seg_tree_right_big[node]=1;
			res%=MOD;
		}

		seg_tree_right_val[node]=res;

		if(seg_tree_right_big[node*2+1] || seg_tree_right_big[node*2] || seg_tree_left_big[node*2+1])
		{
			seg_tree_right_big[node]=1;
		}
	}
}


void build(int l=0, int r=n-1, int node=1)
{
	if(l==r)
	{
		seg_tree_left_val[node]=x[l];
		seg_tree_left_big[node]=0;
		
		seg_tree_right_val[node]=1;
		seg_tree_right_big[node]=0;

		seg_tree_sell_price[node]=y[l];

		return;
	}

	int m=(l+r)/2;

	build(l,m,node*2);
	build(m+1,r,node*2+1);

	merge(node);
}

int query()
{
	return (seg_tree_left_val[1]*seg_tree_sell_price[1])%MOD;
}

void update(int h, int mode, int val, int l=0, int r=n-1, int node=1)
{
	if(l==r)
	{
		if(mode==1)
		{
			x[h]=val;

			seg_tree_left_val[node]=val;
		}

		if(mode==2)
		{
			y[h]=val;

			seg_tree_sell_price[node]=val;
		}

		return;
	}

	int m=(l+r)/2;

	if(h<=m)
	{
		update(h,mode,val,l,m,node*2);
	}

	else
	{
		update(h,mode,val,m+1,r,node*2+1);
	}

	merge(node);
}

int init(int N, int X[], int Y[])
{
	n=N;
	x=X;
	y=Y;

	build();

	return query();
}

int updateX(int pos, int val)
{
	update(pos,1,val);

	return query();
}

int updateY(int pos, int val)
{
	update(pos,2,val);

	return query();
}

Compilation message

horses.cpp: In function 'int query()':
horses.cpp:123:54: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  123 |  return (seg_tree_left_val[1]*seg_tree_sell_price[1])%MOD;
      |                                                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 32752 KB Output is correct
2 Correct 129 ms 33900 KB Output is correct
3 Correct 111 ms 34252 KB Output is correct
4 Correct 114 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 44 ms 31712 KB Output is correct
34 Correct 45 ms 31716 KB Output is correct
35 Correct 62 ms 31520 KB Output is correct
36 Correct 63 ms 31464 KB Output is correct
37 Correct 35 ms 31772 KB Output is correct
38 Correct 42 ms 31776 KB Output is correct
39 Correct 30 ms 31648 KB Output is correct
40 Correct 49 ms 31608 KB Output is correct
41 Correct 29 ms 31668 KB Output is correct
42 Correct 30 ms 31692 KB Output is correct
43 Correct 42 ms 31516 KB Output is correct
44 Correct 50 ms 31468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 75 ms 32832 KB Output is correct
34 Correct 133 ms 33864 KB Output is correct
35 Correct 102 ms 34168 KB Output is correct
36 Correct 119 ms 34060 KB Output is correct
37 Correct 53 ms 33316 KB Output is correct
38 Correct 46 ms 33268 KB Output is correct
39 Correct 63 ms 33112 KB Output is correct
40 Correct 73 ms 32972 KB Output is correct
41 Correct 38 ms 33116 KB Output is correct
42 Correct 42 ms 33212 KB Output is correct
43 Correct 30 ms 32908 KB Output is correct
44 Correct 51 ms 33124 KB Output is correct
45 Correct 32 ms 33032 KB Output is correct
46 Correct 33 ms 32988 KB Output is correct
47 Correct 43 ms 33064 KB Output is correct
48 Correct 44 ms 33068 KB Output is correct
49 Correct 104 ms 34024 KB Output is correct
50 Correct 117 ms 34044 KB Output is correct
51 Correct 94 ms 33884 KB Output is correct
52 Correct 89 ms 33980 KB Output is correct
53 Correct 99 ms 34176 KB Output is correct
54 Correct 86 ms 34128 KB Output is correct
55 Correct 62 ms 33404 KB Output is correct
56 Correct 79 ms 34052 KB Output is correct
57 Correct 57 ms 34116 KB Output is correct
58 Correct 60 ms 34252 KB Output is correct
59 Correct 49 ms 33040 KB Output is correct