Submission #670874

# Submission time Handle Problem Language Result Execution time Memory
670874 2022-12-11T01:25:46 Z LittleCube Horses (IOI15_horses) C++14
100 / 100
179 ms 66648 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

const ll mod = 1'000'000'007;
ll N, x[500005], y[500005];
struct node
{
	ll L = 0, Lmod = 0, R = 0, Rmod = 0, price = 0;
};

ll mul(ll a, ll b)
{
	return min(mod, a * b);
}

node merge(node n, node m)
{
	node ans;
	if (n.price <= min(mod, n.R * m.L) * m.price)
		ans = node{mul(mul(n.L, n.R), m.L),
				   n.Lmod * n.Rmod % mod * m.Lmod % mod,
				   m.R,
				   m.Rmod,
				   m.price};
	else
		ans = node{n.L,
				   n.Lmod,
				   mul(n.R, mul(m.L, m.R)),
				   n.Rmod * m.Lmod % mod * m.Rmod % mod,
				   n.price};
	return ans;
}

node seg[2000005];

void build(ll X[], ll Y[], int i = 1, int L = 0, int R = N - 1)
{
	if (L == R)
		seg[i] = node{X[L], X[L], 1, 1, Y[L]};
	else
	{
		int mid = (L + R) / 2;
		build(X, Y, i << 1, L, mid);
		build(X, Y, i << 1 | 1, mid + 1, R);
		seg[i] = merge(seg[i << 1], seg[i << 1 | 1]);
	}
}

void modify(int pos, ll X, ll Y, int i = 1, int L = 0, int R = N - 1)
{
	if (L == R)
		seg[i] = node{X, X, 1, 1, Y};
	else
	{
		int mid = (L + R) / 2;
		if (pos <= mid)
			modify(pos, X, Y, i << 1, L, mid);
		else
			modify(pos, X, Y, i << 1 | 1, mid + 1, R);
		seg[i] = merge(seg[i << 1], seg[i << 1 | 1]);
	}
}

int init(int n, int X[], int Y[])
{
	N = n;
	for(int i = 0; i < N; i++)
		x[i] = X[i], y[i] = Y[i];
	build(x, y);
	return seg[1].Lmod * seg[1].price % mod;
}

int updateX(int pos, int val)
{
	x[pos] = val;
	modify(pos, x[pos], y[pos]);
	return seg[1].Lmod * seg[1].price % mod;
}

int updateY(int pos, int val)
{
	y[pos] = val;
	modify(pos, x[pos], y[pos]);
	return seg[1].Lmod * seg[1].price % mod;
}

Compilation message

horses.cpp:42:60: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   42 | void build(ll X[], ll Y[], int i = 1, int L = 0, int R = N - 1)
      |                                                          ~~^~~
horses.cpp:55:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   55 | void modify(int pos, ll X, ll Y, int i = 1, int L = 0, int R = N - 1)
      |                                                                ~~^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:75:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   75 |  build(x, y);
      |            ^
horses.cpp:76:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |  return seg[1].Lmod * seg[1].price % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:82:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   82 |  modify(pos, x[pos], y[pos]);
      |                            ^
horses.cpp:83:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   83 |  return seg[1].Lmod * seg[1].price % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:89:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |  modify(pos, x[pos], y[pos]);
      |                            ^
horses.cpp:90:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   90 |  return seg[1].Lmod * seg[1].price % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 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 316 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 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 57828 KB Output is correct
2 Correct 176 ms 66648 KB Output is correct
3 Correct 138 ms 57804 KB Output is correct
4 Correct 156 ms 61696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 452 KB Output is correct
26 Correct 1 ms 468 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 448 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 62 ms 57020 KB Output is correct
34 Correct 63 ms 57112 KB Output is correct
35 Correct 89 ms 64016 KB Output is correct
36 Correct 80 ms 63872 KB Output is correct
37 Correct 52 ms 55172 KB Output is correct
38 Correct 52 ms 56148 KB Output is correct
39 Correct 46 ms 55116 KB Output is correct
40 Correct 60 ms 59084 KB Output is correct
41 Correct 48 ms 55152 KB Output is correct
42 Correct 45 ms 55264 KB Output is correct
43 Correct 58 ms 59340 KB Output is correct
44 Correct 57 ms 59340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 444 KB Output is correct
25 Correct 1 ms 468 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 452 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 452 KB Output is correct
33 Correct 94 ms 57872 KB Output is correct
34 Correct 179 ms 66636 KB Output is correct
35 Correct 145 ms 57804 KB Output is correct
36 Correct 152 ms 61644 KB Output is correct
37 Correct 60 ms 57016 KB Output is correct
38 Correct 61 ms 57108 KB Output is correct
39 Correct 83 ms 63992 KB Output is correct
40 Correct 83 ms 63964 KB Output is correct
41 Correct 52 ms 55164 KB Output is correct
42 Correct 53 ms 56076 KB Output is correct
43 Correct 47 ms 55048 KB Output is correct
44 Correct 61 ms 58984 KB Output is correct
45 Correct 47 ms 55176 KB Output is correct
46 Correct 45 ms 55244 KB Output is correct
47 Correct 58 ms 59492 KB Output is correct
48 Correct 60 ms 59592 KB Output is correct
49 Correct 149 ms 59084 KB Output is correct
50 Correct 150 ms 59032 KB Output is correct
51 Correct 128 ms 65844 KB Output is correct
52 Correct 130 ms 65404 KB Output is correct
53 Correct 143 ms 57420 KB Output is correct
54 Correct 106 ms 58000 KB Output is correct
55 Correct 95 ms 56204 KB Output is correct
56 Correct 114 ms 60888 KB Output is correct
57 Correct 99 ms 56820 KB Output is correct
58 Correct 94 ms 57300 KB Output is correct
59 Correct 58 ms 59468 KB Output is correct