답안 #299269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299269 2020-09-14T15:49:09 Z Hideo 말 (IOI15_horses) C++17
100 / 100
912 ms 56568 KB
#include "horses.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(s) s.begin(), s.end()
#define pb push_back
#define fr first
#define sc second
#define vl vector < ll >
#define pl pair < ll, ll >

const int MN = 5e5 + 7;
const ll mod = 1e9 + 7;

ll t[4 * MN], m[4 * MN];
ll x[MN], y[MN], pr[MN];
set < int > p;
int n;

void build (int v, int l, int r){
    if (l == r){
        t[v] = x[l];
        m[v] = y[l];
    }
    else {
        int mid = (l + r) >> 1;
        build(v + v, l, mid);
        build(v + v + 1, mid + 1, r);
        t[v] = (t[v + v] * t[v + v + 1]) % mod;
        m[v] = max(m[v + v], m[v + v + 1]);
    }
}

void upd (int v, int l, int r, int pos, ll val){
    if (l == r)
        t[v] = val;
    else {
        int mid = (l + r) >> 1;
        if (pos <= mid)
            upd(v + v, l, mid, pos, val);
        else
            upd(v + v + 1, mid + 1, r, pos, val);
        t[v] = (t[v + v] * t[v + v + 1]) % mod;
    }
}

void upd_m (int v, int l, int r, int pos, ll val){
    if (l == r)
        m[v] = val;
    else {
        int mid = (l + r) >> 1;
        if (pos <= mid)
            upd_m(v + v, l, mid, pos, val);
        else
            upd_m(v + v + 1, mid + 1, r, pos, val);
        m[v] = max(m[v + v], m[v + v + 1]);
    }
}

ll get (int v, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr)
        return t[v];
    if (r < ql || qr < l)
        return 1LL;
    int mid = (l + r) >> 1;
    return (get(v + v, l, mid, ql, qr) * get(v + v + 1, mid + 1, r, ql, qr)) % mod;
}

ll get_m (int v, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr)
        return m[v];
    if (r < ql || qr < l)
        return 1LL;
    int mid = (l + r) >> 1;
    return max(get_m(v + v, l, mid, ql, qr), get_m(v + v + 1, mid + 1, r, ql, qr));
}

int answer(){
    vl v;
    v.clear();
    ll s = 1;
    for (int it : p){
        if (s >= mod)
            break;
        int i = -it;
        s *= x[i];
        v.pb(i);
    }
    ll temp = s;
    int sz = v.size();
    ll mx = 0, yy = 0;
    s = 1;
    for (int i = sz - 2; i >= 0; i--){
        s *= x[v[i]];
        if (i)
            yy = get_m(1, 1, n, v[i], v[i - 1] - 1);
        else
            yy = get_m(1, 1, n, v[i], n);
        mx = max(mx, s * yy);
    }
    if (v.back() == 0){
        yy = get_m(1, 1, n, 1, n);
        return max(mx, yy) % mod;
    }
    else {
        if (sz > 1)
            yy = get_m(1, 1, n, v[sz - 1], v[sz - 2] - 1);
        else
            yy = get_m(1, 1, n, v[sz - 1], n);
        return (max(mx, yy) % mod * get(1, 1, n, 1, v[sz - 1])) % mod;
    }
}

int init(int N, int X[], int Y[]){
    n = N;
    p.insert(0);
    x[0] = 1LL;
    y[0] = 1LL;
    for (int i = 1; i <= n; i++){
        x[i] = X[i - 1];
        y[i] = Y[i - 1];
        if (x[i] != 1)
            p.insert(-i);
    }
    build(1, 1, n);
    return answer();
}

int updateX(int pos, int val) {
    pos++;
    if (x[pos] != 1 && val == 1)
        p.erase(-pos);
    else if (x[pos] == 1 && val != 1)
        p.insert(-pos);
    upd(1, 1, n, pos, 1LL * val);
    x[pos] = 1LL * val;
    return answer();
}

int updateY(int pos, int val) {
    pos++;
    y[pos] = 1LL * val;
    upd_m(1, 1, n, pos, 1LL * val);
	return answer();
}

Compilation message

horses.cpp: In function 'int answer()':
horses.cpp:93:20: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   93 |     int sz = v.size();
      |              ~~~~~~^~
horses.cpp:99:51: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   99 |             yy = get_m(1, 1, n, v[i], v[i - 1] - 1);
      |                                                   ^
horses.cpp:99:48: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   99 |             yy = get_m(1, 1, n, v[i], v[i - 1] - 1);
horses.cpp:101:40: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  101 |             yy = get_m(1, 1, n, v[i], n);
      |                                        ^
horses.cpp:106:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  106 |         return max(mx, yy) % mod;
      |                ~~~~~~~~~~~~^~~~~
horses.cpp:110:57: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  110 |             yy = get_m(1, 1, n, v[sz - 1], v[sz - 2] - 1);
      |                                                         ^
horses.cpp:110:54: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  110 |             yy = get_m(1, 1, n, v[sz - 1], v[sz - 2] - 1);
horses.cpp:112:45: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  112 |             yy = get_m(1, 1, n, v[sz - 1], n);
      |                                             ^
horses.cpp:113:62: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  113 |         return (max(mx, yy) % mod * get(1, 1, n, 1, v[sz - 1])) % mod;
      |                                                              ^
horses.cpp:113:65: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  113 |         return (max(mx, yy) % mod * get(1, 1, n, 1, v[sz - 1])) % mod;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:92:8: warning: unused variable 'temp' [-Wunused-variable]
   92 |     ll temp = s;
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 810 ms 53056 KB Output is correct
2 Correct 323 ms 52924 KB Output is correct
3 Correct 356 ms 52984 KB Output is correct
4 Correct 384 ms 53112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 288 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 1 ms 416 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 4 ms 616 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 58 ms 30372 KB Output is correct
34 Correct 54 ms 30328 KB Output is correct
35 Correct 211 ms 55040 KB Output is correct
36 Correct 196 ms 55192 KB Output is correct
37 Correct 134 ms 30332 KB Output is correct
38 Correct 122 ms 42232 KB Output is correct
39 Correct 46 ms 30200 KB Output is correct
40 Correct 180 ms 53624 KB Output is correct
41 Correct 76 ms 30328 KB Output is correct
42 Correct 111 ms 30588 KB Output is correct
43 Correct 175 ms 53880 KB Output is correct
44 Correct 167 ms 53880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 801 ms 54648 KB Output is correct
34 Correct 325 ms 56056 KB Output is correct
35 Correct 338 ms 55032 KB Output is correct
36 Correct 401 ms 55172 KB Output is correct
37 Correct 57 ms 30712 KB Output is correct
38 Correct 54 ms 30584 KB Output is correct
39 Correct 214 ms 55804 KB Output is correct
40 Correct 196 ms 55544 KB Output is correct
41 Correct 131 ms 30712 KB Output is correct
42 Correct 120 ms 42488 KB Output is correct
43 Correct 43 ms 30456 KB Output is correct
44 Correct 177 ms 54008 KB Output is correct
45 Correct 75 ms 30584 KB Output is correct
46 Correct 96 ms 30584 KB Output is correct
47 Correct 186 ms 53880 KB Output is correct
48 Correct 172 ms 53880 KB Output is correct
49 Correct 218 ms 32632 KB Output is correct
50 Correct 190 ms 32504 KB Output is correct
51 Correct 407 ms 56568 KB Output is correct
52 Correct 290 ms 56568 KB Output is correct
53 Correct 912 ms 32608 KB Output is correct
54 Correct 390 ms 45560 KB Output is correct
55 Correct 173 ms 30712 KB Output is correct
56 Correct 302 ms 54904 KB Output is correct
57 Correct 466 ms 31864 KB Output is correct
58 Correct 706 ms 31744 KB Output is correct
59 Correct 164 ms 53880 KB Output is correct