Submission #583854

# Submission time Handle Problem Language Result Execution time Memory
583854 2022-06-26T10:21:52 Z hibiki Horses (IOI15_horses) C++11
77 / 100
1500 ms 107796 KB
// #include "horses.h"
#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007;
#define pb push_back

int n, x[500005], y[500005];
set<int, greater<int>> s;

struct node
{
	long long val;
	node *l, *r;
} *root1, *root2;

node* build1(int l,int r)
{
	node *ptr = new node;
	if(l == r)
	{
		ptr->val = x[l];
		return ptr;
	}
	int mid = (l + r) / 2;
	ptr->l = build1(l, mid);
	ptr->r = build1(mid + 1, r);
	ptr->val = ptr->l->val * ptr->r->val;
    ptr->val %= mod;
    return ptr;
}

node* build2(int l,int r)
{
	node *ptr = new node;
	if(l == r)
	{
		ptr->val = y[l];
		return ptr;
	}
	int mid = (l + r) / 2;
	ptr->l = build2(l, mid);
	ptr->r = build2(mid + 1, r);
	ptr->val = max(ptr->l->val, ptr->r->val);
    return ptr;
}

int ll,rr;
long long que1(node *ptr, int l,int r)
{
    if(ll <= l && r <= rr) return ptr->val;
    if(r < ll || rr < l) return 1;
    int mid = (l + r) / 2;
    return (que1(ptr->l, l, mid) * que1(ptr->r, mid + 1, r)) % mod;
}

int que2(node *ptr, int l,int r)
{
    if(ll <= l && r <= rr) return ptr->val;
    if(r < ll || rr < l) return 0;
    int mid = (l + r) / 2;
    return max(que2(ptr->l, l, mid),que2(ptr->r, mid + 1, r));
}

int up_po,up_val;
void up1(node *ptr, int l,int r)
{
    if(l == r)
    {
        ptr->val = up_val;
        return ;
    }
    int mid = (l + r) / 2;
    if(up_po <= mid) up1(ptr->l, l, mid);
    else up1(ptr->r, mid + 1, r);
    ptr->val = ptr->l->val * ptr->r->val;
    ptr->val %= mod;
}

void up2(node *ptr, int l,int r)
{
    if(l == r)
    {
        ptr->val = up_val;
        return ;
    }
    int mid = (l + r) / 2;
    if(up_po <= mid) up2(ptr->l, l, mid);
    else up2(ptr->r, mid + 1, r);
    ptr->val = max(ptr->l->val, ptr->r->val);
}

int cal()
{
	vector<int> idx = { n };
	long long val = 1;
	for(int sidx : s)
	{
		idx.pb(sidx);
		val *= x[sidx];

		if (val > 1e9 + 5)
			break;
	}

	if(val <= 1e9 + 5 && idx.back() != 0)
		idx.pb(0);
	reverse(idx.begin(), idx.end());

	long long mx = 0;
    int best = 0, ybest = 0;
	for(int i = 0; i+1 < idx.size(); i++)
	{
        ll = idx[i];
        rr = idx[i + 1] - 1;
		int ymax = que2(root2, 0, n - 1);
        ll = idx[1];
        rr = idx[i];
		long long xval = que1(root1, 0, n - 1);
		if (ymax * xval > mx)
			mx = ymax * xval, best = i, ybest = ymax;
	}

    ll = 0;
    rr = idx[best];
	return ((que1(root1, 0, n - 1) * ybest) ) % mod;
}

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];

    root1 = build1(0, n - 1);
    root2 = build2(0, n - 1);

	for(int i = 0; i < n; i++)
        if(x[i] != 1)
		      s.insert(i);

	return cal();
}

int updateX(int pos, int val)
{
	x[pos] = val;
    up_po = pos;
    up_val = val;
	up1(root1, 0, n - 1);
	if (val == 1) s.erase(pos);
	else s.insert(pos);

	return cal();
}

int updateY(int pos, int val)
{
	y[pos] = val;
    up_po = pos;
    up_val = val;
	up2(root2, 0, n - 1);
	return cal();
}

Compilation message

horses.cpp: In function 'int que2(node*, int, int)':
horses.cpp:59:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   59 |     if(ll <= l && r <= rr) return ptr->val;
      |                                   ~~~~~^~~
horses.cpp: In function 'int cal()':
horses.cpp:102:7: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  102 |   if (val > 1e9 + 5)
      |       ^~~
horses.cpp:106:5: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  106 |  if(val <= 1e9 + 5 && idx.back() != 0)
      |     ^~~
horses.cpp:112:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |  for(int i = 0; i+1 < idx.size(); i++)
      |                 ~~~~^~~~~~~~~~~~
horses.cpp:126:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  126 |  return ((que1(root1, 0, n - 1) * ybest) ) % mod;
      |                                            ^
# 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 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 1 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 1 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
# 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 1 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 1 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 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 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 500 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 8 ms 480 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 6 ms 480 KB Output is correct
32 Correct 10 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1331 ms 95196 KB Output is correct
2 Correct 449 ms 107796 KB Output is correct
3 Correct 527 ms 98940 KB Output is correct
4 Correct 637 ms 102808 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 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 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 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 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 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 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 484 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 452 KB Output is correct
27 Correct 8 ms 492 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 448 KB Output is correct
30 Correct 3 ms 528 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 7 ms 484 KB Output is correct
33 Correct 115 ms 74812 KB Output is correct
34 Correct 127 ms 74824 KB Output is correct
35 Correct 258 ms 105092 KB Output is correct
36 Correct 233 ms 105044 KB Output is correct
37 Correct 250 ms 73036 KB Output is correct
38 Correct 178 ms 85728 KB Output is correct
39 Correct 111 ms 72780 KB Output is correct
40 Correct 231 ms 100208 KB Output is correct
41 Correct 155 ms 72780 KB Output is correct
42 Correct 204 ms 72992 KB Output is correct
43 Correct 215 ms 100500 KB Output is correct
44 Correct 213 ms 100492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 0 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 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 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 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 452 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 8 ms 480 KB Output is correct
28 Correct 3 ms 452 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 6 ms 484 KB Output is correct
32 Correct 7 ms 468 KB Output is correct
33 Correct 1352 ms 98944 KB Output is correct
34 Correct 464 ms 107724 KB Output is correct
35 Correct 493 ms 98896 KB Output is correct
36 Correct 610 ms 102816 KB Output is correct
37 Correct 119 ms 74880 KB Output is correct
38 Correct 109 ms 74812 KB Output is correct
39 Correct 272 ms 105128 KB Output is correct
40 Correct 243 ms 105088 KB Output is correct
41 Correct 246 ms 73044 KB Output is correct
42 Correct 185 ms 85816 KB Output is correct
43 Correct 104 ms 72788 KB Output is correct
44 Correct 247 ms 100192 KB Output is correct
45 Correct 162 ms 72864 KB Output is correct
46 Correct 204 ms 72876 KB Output is correct
47 Correct 217 ms 100556 KB Output is correct
48 Correct 216 ms 100532 KB Output is correct
49 Correct 336 ms 77856 KB Output is correct
50 Correct 277 ms 77832 KB Output is correct
51 Correct 525 ms 106956 KB Output is correct
52 Correct 359 ms 106560 KB Output is correct
53 Execution timed out 1572 ms 76152 KB Time limit exceeded
54 Halted 0 ms 0 KB -