답안 #127942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127942 2019-07-10T08:50:49 Z ekrem 말 (IOI15_horses) C++
100 / 100
1006 ms 57428 KB
#include "horses.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
ll ans[MAXN];
set < int > s;
set < int > :: iterator it;

int islem(int d, int a, int b){
	if(!d)
		return max(a, b);
	return 1ll*a*b%mod;
}

void bu(int d, int k, int bas, int son){
	if(bas == son){
		seg[d][k] = (!d)?y[bas]:x[bas];
		return;
	}
	bu(d, sol, bas, orta);
	bu(d, sag, orta + 1, son);
	seg[d][k] = islem(d, seg[d][sol], seg[d][sag]);
}

void up(int d, int k, int bas, int son, int x, int y){
	if(bas == son){
		seg[d][k] = y;
		return;
	}
	if(x <= orta)
		up(d, sol, bas, orta, x, y);
	else
		up(d, sag, orta + 1, son, x, y);
	seg[d][k] = islem(d, seg[d][sol], seg[d][sag]);
}

int qu(int d, int k, int bas, int son, int x, int y){
	if(bas > y or son < x)
		return 1;
	if(bas >= x and son <= y)
		return seg[d][k];
	return islem(d, qu(d, sol, bas, orta, x, y), qu(d, sag, orta + 1, son, x, y));
}

int ansbul(){
	if(s.size() == 2)
		return qu(0, 1, 1, n, 1, n);
	k = 0;
	ll of = 1;
	it = s.end();it--;
	while(1){
		z[++k] = *it;
		// cout << *it << endl;
		of = of*x[z[k]];
		if(it == s.begin())
			break;
		it--;
		// cout << of << endl;
		if(of > inf){
			// k--;
			break;
		}
	}
	// cout << k << endl;
	reverse(z + 1, z + k + 1);
	// for(int i = 1; i <= k; i++)cout << x[z[i]] << " ";cout << endl;
	ll crp = qu(1, 1, 1, n, 1, z[1]), mx = 1, su = 1;
	for(int i = 2; i <= k; i++){
		mx = max(mx, 1ll*ans[z[i - 1]]*su);
		su *= x[z[i]];
	}
	return (mx%mod)*crp%mod;
}

void ekle(int pos){
	s.insert(pos);
	it = s.find(pos);
	it++;
	int x = *it;
	ans[pos] = qu(0, 1, 1, n, pos, x - 1);
	it--;
	it--;
	ans[*it] = qu(0, 1, 1, n, *it, pos - 1);
}

int init(int nn, int X[], int Y[]) {n = nn;
	x[0] = x[n + 1] = 1;
	for(int i = 1; i <= n; i++){
		x[i] = X[i - 1];
		y[i] = Y[i - 1];
	}
	bu(0, 1, 1, n);
	bu(1, 1, 1, n);
	s.insert(n + 1);
	s.insert(0);
	for(int i = 1; i <= n; i++)
		if(x[i] > 1)
			ekle(i);
	return ansbul();
}

int updateX(int pos, int val) {pos++;
	if(s.count(pos)){
		it = s.find(pos);
		it--;
		s.erase(pos);
		int x = *it;
		it++;
		ans[x] = qu(0, 1, 1, n, x, *it - 1);
	}
	x[pos] = val;
	up(1, 1, 1, n, pos, val);
	if(val > 1)
		ekle(pos);
	return ansbul();
}

int updateY(int pos, int val) {pos++;
	up(0, 1, 1, n, pos, val);
	it = s.upper_bound(pos);
	int y = *it;
	it--;
	ans[*it] = qu(0, 1, 1, n, *it, y - 1);
	return ansbul();
}

Compilation message

horses.cpp: In function 'int islem(int, int, int)':
horses.cpp:27:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return 1ll*a*b%mod;
                ^
horses.cpp: In function 'void bu(int, int, int, int)':
horses.cpp:30:39: warning: declaration of 'k' shadows a global declaration [-Wshadow]
 void bu(int d, int k, int bas, int son){
                                       ^
horses.cpp:19:8: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
        ^
horses.cpp: In function 'void up(int, int, int, int, int, int)':
horses.cpp:40:53: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 void up(int d, int k, int bas, int son, int x, int y){
                                                     ^
horses.cpp:19:24: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
                        ^
horses.cpp:40:53: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void up(int d, int k, int bas, int son, int x, int y){
                                                     ^
horses.cpp:19:15: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
               ^
horses.cpp:40:53: warning: declaration of 'k' shadows a global declaration [-Wshadow]
 void up(int d, int k, int bas, int son, int x, int y){
                                                     ^
horses.cpp:19:8: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
        ^
horses.cpp: In function 'int qu(int, int, int, int, int, int)':
horses.cpp:52:52: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 int qu(int d, int k, int bas, int son, int x, int y){
                                                    ^
horses.cpp:19:24: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
                        ^
horses.cpp:52:52: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 int qu(int d, int k, int bas, int son, int x, int y){
                                                    ^
horses.cpp:19:15: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
               ^
horses.cpp:52:52: warning: declaration of 'k' shadows a global declaration [-Wshadow]
 int qu(int d, int k, int bas, int son, int x, int y){
                                                    ^
horses.cpp:19:8: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
        ^
horses.cpp: In function 'int ansbul()':
horses.cpp:87:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return (mx%mod)*crp%mod;
                     ^
horses.cpp: In function 'void ekle(int)':
horses.cpp:94:6: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  int x = *it;
      ^
horses.cpp:19:15: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
               ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:122:7: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   int x = *it;
       ^
horses.cpp:19:15: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
               ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:136:6: warning: declaration of 'y' shadows a global declaration [-Wshadow]
  int y = *it;
      ^
horses.cpp:19:24: note: shadowed declaration is here
 int n, k, kk, x[MAXN], y[MAXN], z[MAXN], seg[2][4*MAXN];
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 508 KB Output is correct
27 Correct 3 ms 508 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 690 ms 44792 KB Output is correct
2 Correct 920 ms 44936 KB Output is correct
3 Correct 899 ms 44920 KB Output is correct
4 Correct 1006 ms 44872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 3 ms 380 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 3 ms 556 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 508 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 62 ms 20644 KB Output is correct
34 Correct 61 ms 20600 KB Output is correct
35 Correct 608 ms 44284 KB Output is correct
36 Correct 607 ms 44396 KB Output is correct
37 Correct 51 ms 18936 KB Output is correct
38 Correct 311 ms 32860 KB Output is correct
39 Correct 42 ms 16888 KB Output is correct
40 Correct 586 ms 44380 KB Output is correct
41 Correct 41 ms 17016 KB Output is correct
42 Correct 44 ms 16888 KB Output is correct
43 Correct 576 ms 44248 KB Output is correct
44 Correct 589 ms 44280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 4 ms 508 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 697 ms 45324 KB Output is correct
34 Correct 927 ms 57428 KB Output is correct
35 Correct 895 ms 48576 KB Output is correct
36 Correct 997 ms 52624 KB Output is correct
37 Correct 62 ms 24184 KB Output is correct
38 Correct 63 ms 24124 KB Output is correct
39 Correct 622 ms 54788 KB Output is correct
40 Correct 604 ms 54772 KB Output is correct
41 Correct 51 ms 20728 KB Output is correct
42 Correct 309 ms 35516 KB Output is correct
43 Correct 47 ms 18428 KB Output is correct
44 Correct 591 ms 49860 KB Output is correct
45 Correct 41 ms 18680 KB Output is correct
46 Correct 44 ms 18680 KB Output is correct
47 Correct 578 ms 50348 KB Output is correct
48 Correct 578 ms 50280 KB Output is correct
49 Correct 227 ms 27512 KB Output is correct
50 Correct 232 ms 27512 KB Output is correct
51 Correct 752 ms 56792 KB Output is correct
52 Correct 713 ms 56132 KB Output is correct
53 Correct 216 ms 23928 KB Output is correct
54 Correct 445 ms 39416 KB Output is correct
55 Correct 121 ms 19576 KB Output is correct
56 Correct 707 ms 51696 KB Output is correct
57 Correct 109 ms 20344 KB Output is correct
58 Correct 142 ms 20840 KB Output is correct
59 Correct 579 ms 50348 KB Output is correct