Submission #560963

# Submission time Handle Problem Language Result Execution time Memory
560963 2022-05-12T05:50:41 Z AriaH Horses (IOI15_horses) C++17
17 / 100
478 ms 37632 KB
#include "horses.h"
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 5e5 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;

ll n, A[N], B[N];

struct node
{
	ll z, mx, my;
	void init(int a, int b)
	{
		z = a;
		mx = a;
		my = b;
	}
	friend node operator | (node a, node b)
	{
		node ret;
		ret.z = a.z * b.z % mod;
		ret.mx = max(a.mx, b.mx);
		ret.my = max(a.my, b.my);
		return ret;
	}
} seg[N << 2];

void build(int v = 1, int tl = 0, int tr = n - 1)
{
	if(tl == tr)
	{
		seg[v].init(A[tl], B[tl]);
		return;
	}
	int mid = (tl + tr) >> 1;
	build(v << 1, tl, mid), build(v << 1 | 1, mid + 1, tr);
	seg[v] = seg[v << 1] | seg[v << 1 | 1];
}

void Change(int p, int v = 1, int tl = 0, int tr = n - 1)
{
	if(tl == tr)
	{
		seg[v].init(A[p], B[p]);
		return;
	}
	int mid = (tl + tr) >> 1;
	if(p <= mid) Change(p, v << 1, tl, mid);
	else Change(p, v << 1 | 1, mid + 1, tr);
	seg[v] = seg[v << 1] | seg[v << 1 | 1];
}

pii get(int pos, int v = 1, int tl = 0, int tr = n - 1)
{
	if(tl > pos) return Mp(-1, -1);
	if(seg[v].mx == 1) return Mp(tl, seg[v].my);
	if(tl == tr) return Mp(tl, B[tl]);
	int mid = (tl + tr) >> 1;
	pii cu = get(pos, v << 1 | 1, mid + 1, tr);
	if(A[cu.F] > 1)
	{
		return cu;
	}
	pii now = get(pos, v << 1, tl, mid);
	return Mp(now.F, max(now.S, cu.S));
}

ll ask(int l, int r, int v = 1, int tl = 0, int tr = n - 1)
{
	if(l > tr || r < tl || l > r) return 1;
	if(l <= tl && tr <= r) return seg[v].z;
	int mid = (tl + tr) >> 1;
	return ask(l, r, v << 1, tl, mid) * ask(l, r, v << 1 | 1, mid + 1, tr) % mod;
}

int solve()
{
	int id = n - 1;
	ll zarb = 1, best = 0;
	while(id >= 0)
	{
		pii now = get(id);
		zarb *= A[now.F];
		best = max(best, (ll)now.S);
		id = now.F - 1;
		///printf("id = %d best = %lld zarb = %lld\n", id, best, zarb);
		if(zarb >= 1e9) break;
		best *= A[now.F];
	}
	best %= mod;
	if(id == -1)
	{
		return best;
	}
	return best * ask(0, id) % mod;
}

int init(int _N, int X[], int Y[])
{
	n = _N;
	for(int i = 0; i < n; i ++) A[i] = X[i], B[i] = Y[i];
	build();
	return solve();
}

int updateX(int pos, int val)
{
	assert(val > 0);
	A[pos] = val;
	Change(pos);
	return solve();
}

int updateY(int pos, int val)
{
	assert(val > 0);
	B[pos] = val;
	Change(pos);
	return solve();
}

Compilation message

horses.cpp:47:46: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   47 | void build(int v = 1, int tl = 0, int tr = n - 1)
      |                                            ~~^~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:51:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |   seg[v].init(A[tl], B[tl]);
      |               ~~~~^
horses.cpp:51:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |   seg[v].init(A[tl], B[tl]);
      |                      ~~~~^
horses.cpp: At global scope:
horses.cpp:59:54: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   59 | void Change(int p, int v = 1, int tl = 0, int tr = n - 1)
      |                                                    ~~^~~
horses.cpp: In function 'void Change(int, int, int, int)':
horses.cpp:63:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   63 |   seg[v].init(A[p], B[p]);
      |               ~~~^
horses.cpp:63:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   63 |   seg[v].init(A[p], B[p]);
      |                     ~~~^
horses.cpp: At global scope:
horses.cpp:72:52: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 | pii get(int pos, int v = 1, int tl = 0, int tr = n - 1)
      |                                                  ~~^~~
horses.cpp:87:56: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   87 | ll ask(int l, int r, int v = 1, int tl = 0, int tr = n - 1)
      |                                                      ~~^~~
horses.cpp: In function 'int solve()':
horses.cpp:97:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   97 |  int id = n - 1;
      |           ~~^~~
horses.cpp:101:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  101 |   pii now = get(id);
      |                   ^
horses.cpp:106:6: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
  106 |   if(zarb >= 1e9) break;
      |      ^~~~
horses.cpp:112:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  112 |   return best;
      |          ^~~~
horses.cpp:114:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  114 |  return best * ask(0, id) % mod;
      |                         ^
horses.cpp:114:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  114 |  return best * ask(0, id) % mod;
      |         ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:121:8: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  121 |  build();
      |        ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:129:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  129 |  Change(pos);
      |            ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:137:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  137 |  Change(pos);
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 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 0 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 478 ms 37632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 224 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 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 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -