답안 #43589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43589 2018-03-18T04:09:19 Z PowerOfNinjaGo 말 (IOI15_horses) C++14
100 / 100
1473 ms 258972 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
#include "grader.cpp"
#else
#include "horses.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 500005;
const int md = 1e9 + 7;
ll prod[4*maxn];
ll most[4*maxn];
int x[4*maxn];
int y[4*maxn];
int n;
int mul(ll a, ll b)
{
	a %= md; b %= md;
	return (1LL*a*b)%md;
}
void update(ll *st, int x, int dx, int md, int p = 1, int L = 1, int R = n)
{
	if(L> x || R< x) return;
	if(L == R && L == x)
	{
		st[p] = dx;
		return;
	}
	int M = (L+R)/2;
	//printf("%d %d %d\n", L, R, M);
	//system("pause");
	update(st, x, dx, md, 2*p, L, M); update(st, x, dx, md, 2*p+1, M+1, R);
	if(md == 1) st[p] = mul(st[2*p], st[2*p+1]);
	else st[p] = max(st[2*p], st[2*p+1]);
}
ll ask(ll *st, int i, int j, int md, int p = 1, int L = 1, int R = n)
{
	if(i> R || j< L) return 1;
	if(i<= L && R<= j) return st[p];
	int M = (L+R)/2;
	ll x = ask(st, i, j, md, 2*p, L, M);
	ll y = ask(st, i, j, md, 2*p+1, M+1, R);
	if(md == 1) return mul(x, y);
	else return max(x, y);
}
set<int> bst;
int query()
{
	vi tmp;
	ll product = 1;
	int bef = -1;
	for(auto it = bst.rbegin(); it != bst.rend(); it++)
	{
		if(x[*it]*product<= 1e9)
		{
			product *= x[*it];
			tmp.pb(*it);
		}
		else
		{
			bef = *it;
			break;
		}
	}
	reverse(tmp.begin(), tmp.end());
	if(tmp.empty()) return ask(most, 1, n, 2);
	int q = tmp.size();
	if(bef == -1)
	{
		ll best = ask(most, 1, tmp[0]-1, 2);
		ll run = 1;
		for(int i = 0; i< q; i++)
		{
			run *= x[tmp[i]];
			int rend = i+1< q?tmp[i+1]:n+1;
			best = max(best, run*ask(most, tmp[i], rend-1, 2));
		}
		return best%md;
	}
	ll best = ask(most, bef, tmp[0]-1, 2);
	ll run = 1;
	for(int i = 0; i< q; i++)
	{
		run *= x[tmp[i]];
		int rend = i+1<q?tmp[i+1]:n+1;
		best = max(best, run*ask(most, tmp[i], rend-1, 2));
	}
	return mul(best, ask(prod, 1, tmp[0]-1, 1));
}
int init(int N, int X[], int Y[])
{
	n = N;
	for(int i = 1; i<= n; i++) x[i] = X[i-1], y[i] = Y[i-1];
	for(int i = 1; i<= N; i++) update(prod, i, x[i], 1);
	for(int i = 1; i<= N; i++) update(most, i, y[i], 2);
	for(int i = 1; i<= N; i++) if(x[i]> 1) bst.insert(i);
	return query();
}
int updateX(int pos, int val)
{
	pos++;
	x[pos] = val;
	if(val> 1) bst.insert(pos);
	else bst.erase(pos);
	update(prod, pos, val, 1);
	return query();
}
int updateY(int pos, int val)
{
	pos++;
	y[pos] = val;
	update(most, pos, val, 2);
	return query();
}

Compilation message

horses.cpp: In function 'int mul(ll, ll)':
horses.cpp:25:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return (1LL*a*b)%md;
                   ^
horses.cpp: In function 'void update(ll*, int, int, int, int, int, int)':
horses.cpp:27:75: warning: declaration of 'md' shadows a global declaration [-Wshadow]
 void update(ll *st, int x, int dx, int md, int p = 1, int L = 1, int R = n)
                                                                           ^
horses.cpp:16:11: note: shadowed declaration is here
 const int md = 1e9 + 7;
           ^
horses.cpp:27:75: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update(ll *st, int x, int dx, int md, int p = 1, int L = 1, int R = n)
                                                                           ^
horses.cpp:19:5: note: shadowed declaration is here
 int x[4*maxn];
     ^
horses.cpp: In function 'll ask(ll*, int, int, int, int, int, int)':
horses.cpp:42:69: warning: declaration of 'md' shadows a global declaration [-Wshadow]
 ll ask(ll *st, int i, int j, int md, int p = 1, int L = 1, int R = n)
                                                                     ^
horses.cpp:16:11: note: shadowed declaration is here
 const int md = 1e9 + 7;
           ^
horses.cpp:47:5: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  ll x = ask(st, i, j, md, 2*p, L, M);
     ^
horses.cpp:19:5: note: shadowed declaration is here
 int x[4*maxn];
     ^
horses.cpp:48:5: warning: declaration of 'y' shadows a global declaration [-Wshadow]
  ll y = ask(st, i, j, md, 2*p+1, M+1, R);
     ^
horses.cpp:20:5: note: shadowed declaration is here
 int y[4*maxn];
     ^
horses.cpp: In function 'int query()':
horses.cpp:72:42: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  if(tmp.empty()) return ask(most, 1, n, 2);
                                          ^
horses.cpp:73:19: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int q = tmp.size();
                   ^
horses.cpp:84:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return best%md;
               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 404 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 1 ms 552 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 1 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 1 ms 728 KB Output is correct
15 Correct 1 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 1 ms 728 KB Output is correct
18 Correct 1 ms 728 KB Output is correct
19 Correct 1 ms 728 KB Output is correct
20 Correct 2 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 728 KB Output is correct
2 Correct 2 ms 728 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 1 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 1 ms 728 KB Output is correct
11 Correct 1 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 1 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 1 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 1 ms 728 KB Output is correct
21 Correct 2 ms 728 KB Output is correct
22 Correct 2 ms 728 KB Output is correct
23 Correct 3 ms 728 KB Output is correct
24 Correct 3 ms 780 KB Output is correct
25 Correct 4 ms 816 KB Output is correct
26 Correct 3 ms 848 KB Output is correct
27 Correct 8 ms 848 KB Output is correct
28 Correct 4 ms 916 KB Output is correct
29 Correct 3 ms 916 KB Output is correct
30 Correct 3 ms 936 KB Output is correct
31 Correct 6 ms 936 KB Output is correct
32 Correct 7 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1473 ms 49728 KB Output is correct
2 Correct 825 ms 49728 KB Output is correct
3 Correct 888 ms 49728 KB Output is correct
4 Correct 1010 ms 49804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 49804 KB Output is correct
2 Correct 1 ms 49804 KB Output is correct
3 Correct 1 ms 49804 KB Output is correct
4 Correct 1 ms 49804 KB Output is correct
5 Correct 1 ms 49804 KB Output is correct
6 Correct 1 ms 49804 KB Output is correct
7 Correct 1 ms 49804 KB Output is correct
8 Correct 2 ms 49804 KB Output is correct
9 Correct 2 ms 49804 KB Output is correct
10 Correct 1 ms 49804 KB Output is correct
11 Correct 1 ms 49804 KB Output is correct
12 Correct 1 ms 49804 KB Output is correct
13 Correct 1 ms 49804 KB Output is correct
14 Correct 1 ms 49804 KB Output is correct
15 Correct 1 ms 49804 KB Output is correct
16 Correct 1 ms 49804 KB Output is correct
17 Correct 1 ms 49804 KB Output is correct
18 Correct 2 ms 49804 KB Output is correct
19 Correct 1 ms 49804 KB Output is correct
20 Correct 1 ms 49804 KB Output is correct
21 Correct 1 ms 49804 KB Output is correct
22 Correct 2 ms 49804 KB Output is correct
23 Correct 3 ms 49804 KB Output is correct
24 Correct 3 ms 49804 KB Output is correct
25 Correct 4 ms 49804 KB Output is correct
26 Correct 3 ms 49804 KB Output is correct
27 Correct 7 ms 49804 KB Output is correct
28 Correct 4 ms 49804 KB Output is correct
29 Correct 3 ms 49804 KB Output is correct
30 Correct 3 ms 49804 KB Output is correct
31 Correct 5 ms 49804 KB Output is correct
32 Correct 7 ms 49804 KB Output is correct
33 Correct 398 ms 49804 KB Output is correct
34 Correct 407 ms 49804 KB Output is correct
35 Correct 627 ms 67736 KB Output is correct
36 Correct 638 ms 78548 KB Output is correct
37 Correct 492 ms 78548 KB Output is correct
38 Correct 490 ms 78548 KB Output is correct
39 Correct 386 ms 78548 KB Output is correct
40 Correct 579 ms 91612 KB Output is correct
41 Correct 437 ms 91612 KB Output is correct
42 Correct 479 ms 91612 KB Output is correct
43 Correct 580 ms 102288 KB Output is correct
44 Correct 567 ms 108524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 108524 KB Output is correct
2 Correct 2 ms 108524 KB Output is correct
3 Correct 1 ms 108524 KB Output is correct
4 Correct 2 ms 108524 KB Output is correct
5 Correct 2 ms 108524 KB Output is correct
6 Correct 1 ms 108524 KB Output is correct
7 Correct 1 ms 108524 KB Output is correct
8 Correct 1 ms 108524 KB Output is correct
9 Correct 2 ms 108524 KB Output is correct
10 Correct 2 ms 108524 KB Output is correct
11 Correct 2 ms 108524 KB Output is correct
12 Correct 2 ms 108524 KB Output is correct
13 Correct 2 ms 108524 KB Output is correct
14 Correct 1 ms 108524 KB Output is correct
15 Correct 2 ms 108524 KB Output is correct
16 Correct 2 ms 108524 KB Output is correct
17 Correct 1 ms 108524 KB Output is correct
18 Correct 2 ms 108524 KB Output is correct
19 Correct 1 ms 108524 KB Output is correct
20 Correct 1 ms 108524 KB Output is correct
21 Correct 1 ms 108524 KB Output is correct
22 Correct 1 ms 108524 KB Output is correct
23 Correct 3 ms 108524 KB Output is correct
24 Correct 3 ms 108524 KB Output is correct
25 Correct 4 ms 108524 KB Output is correct
26 Correct 3 ms 108524 KB Output is correct
27 Correct 7 ms 108524 KB Output is correct
28 Correct 4 ms 108524 KB Output is correct
29 Correct 3 ms 108524 KB Output is correct
30 Correct 3 ms 108524 KB Output is correct
31 Correct 5 ms 108524 KB Output is correct
32 Correct 7 ms 108524 KB Output is correct
33 Correct 1439 ms 113564 KB Output is correct
34 Correct 869 ms 126072 KB Output is correct
35 Correct 888 ms 129864 KB Output is correct
36 Correct 997 ms 137656 KB Output is correct
37 Correct 431 ms 137656 KB Output is correct
38 Correct 399 ms 137656 KB Output is correct
39 Correct 665 ms 155332 KB Output is correct
40 Correct 642 ms 166288 KB Output is correct
41 Correct 495 ms 166288 KB Output is correct
42 Correct 512 ms 166288 KB Output is correct
43 Correct 401 ms 166288 KB Output is correct
44 Correct 622 ms 179376 KB Output is correct
45 Correct 421 ms 179376 KB Output is correct
46 Correct 485 ms 179376 KB Output is correct
47 Correct 609 ms 189804 KB Output is correct
48 Correct 645 ms 196024 KB Output is correct
49 Correct 671 ms 196024 KB Output is correct
50 Correct 648 ms 196024 KB Output is correct
51 Correct 924 ms 219068 KB Output is correct
52 Correct 773 ms 230508 KB Output is correct
53 Correct 1453 ms 230508 KB Output is correct
54 Correct 871 ms 230508 KB Output is correct
55 Correct 562 ms 230508 KB Output is correct
56 Correct 818 ms 247480 KB Output is correct
57 Correct 1137 ms 247480 KB Output is correct
58 Correct 1255 ms 247480 KB Output is correct
59 Correct 637 ms 258972 KB Output is correct