답안 #970588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970588 2024-04-26T18:00:47 Z rahidilbayramli 말 (IOI15_horses) C++17
100 / 100
527 ms 54732 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include "horses.h"
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9+7, sz = 5e5+5;
const ll inf = 2e9;
int x[sz], y[sz], n;
pii segtree[4*sz];
set<pii>st;
int m(ll x, int y)
{
    return ((x % mod) * y) % mod;
}
void build(int v, int l, int r)
{
    if(l == r)
    {
        segtree[v].f = x[l];
        segtree[v].s = y[l];
    }
    else
    {
        int mid = (l + r) / 2;
        build(2*v, l, mid);
        build(2*v+1, mid+1, r);
        segtree[v].f = m(segtree[2*v].f, segtree[2*v+1].f);
        segtree[v].s = max(segtree[2*v].s, segtree[2*v+1].s);
    }
}
void update(int v, int l, int r, int type, int pos, int val)
{
    if(l == r)
    {
        if(type == 1)
            segtree[v].f = val;
        else
            segtree[v].s = val;
    }
    else
    {
        int mid = (l + r) / 2;
        if(pos <= mid)
            update(2*v, l, mid, type, pos, val);
        else
            update(2*v+1, mid+1, r, type, pos, val);
        segtree[v].f = m(segtree[2*v].f, segtree[2*v+1].f);
        segtree[v].s = max(segtree[2*v].s, segtree[2*v+1].s);
    }
}
pii findans(int v, int l, int r, int tl, int tr)
{
    if(tl > tr)
        return {1, INT_MIN};
    if(l == tl && r == tr)
        return segtree[v];
    else
    {
        int mid = (l + r) / 2;
        pii lans, rans, ans;
        lans = findans(2*v, l, mid, tl, min(mid, tr));
        rans = findans(2*v+1, mid+1, r, max(mid+1, tl), tr);
        ans.f = m(lans.f, rans.f);
        ans.s = max(lans.s, rans.s);
        return ans;
    }
}
int ans()
{
    ll res = 1;
    int lst = n + 1;
    for(auto u : st)
    {
        res = max(res, (ll)(findans(1, 1, n, -u.f, lst-1).s));
        res *= u.s;
        if(res >= inf)
            return m(res, findans(1, 1, n, 1, -u.f-1).f);
        lst = -u.f;
    }
    return res % mod;
}
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];
        if(x[i] >= 2 || i == 1)
            st.insert({-i, x[i]});
    }
    build(1, 1, N);
    return ans();
}
int updateX(int pos, int val) {
    pos++;
    update(1, 1, n, 1, pos, val);
    if(x[pos] >= 2 || pos == 1)
    {
        if(st.find({-pos, x[pos]}) != st.end())
            st.erase({-pos, x[pos]});
    }
    x[pos] = val;
    if(x[pos] >= 2 || pos == 1)
        st.insert({-pos, x[pos]});
    return ans();
}
int updateY(int pos, int val) {
    update(1, 1, n, 2, pos+1, val);
    return ans();
}

Compilation message

horses.cpp: In function 'int m(long long int, int)':
horses.cpp:26:17: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   26 | int m(ll x, int y)
      |             ~~~~^
horses.cpp:23:12: note: shadowed declaration is here
   23 | int x[sz], y[sz], n;
      |            ^
horses.cpp:26:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   26 | int m(ll x, int y)
      |          ^
horses.cpp:23:5: note: shadowed declaration is here
   23 | int x[sz], y[sz], n;
      |     ^
horses.cpp:28:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   28 |     return ((x % mod) * y) % mod;
      |            ~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ans()':
horses.cpp:95:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   95 |     return res % mod;
      |            ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4452 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4536 KB Output is correct
11 Correct 1 ms 4540 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4448 KB Output is correct
16 Correct 1 ms 4448 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4544 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 2 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 3 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4548 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 487 ms 46012 KB Output is correct
2 Correct 265 ms 54732 KB Output is correct
3 Correct 264 ms 45992 KB Output is correct
4 Correct 329 ms 49904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4640 KB Output is correct
4 Correct 1 ms 4540 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4504 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 3 ms 4532 KB Output is correct
28 Correct 2 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4440 KB Output is correct
33 Correct 34 ms 21720 KB Output is correct
34 Correct 29 ms 21888 KB Output is correct
35 Correct 136 ms 52048 KB Output is correct
36 Correct 137 ms 52164 KB Output is correct
37 Correct 68 ms 19900 KB Output is correct
38 Correct 70 ms 32844 KB Output is correct
39 Correct 23 ms 19792 KB Output is correct
40 Correct 119 ms 47188 KB Output is correct
41 Correct 43 ms 19804 KB Output is correct
42 Correct 55 ms 19804 KB Output is correct
43 Correct 112 ms 47612 KB Output is correct
44 Correct 108 ms 47484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4540 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 4 ms 4600 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4560 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4592 KB Output is correct
32 Correct 3 ms 4544 KB Output is correct
33 Correct 470 ms 45952 KB Output is correct
34 Correct 264 ms 54608 KB Output is correct
35 Correct 266 ms 45856 KB Output is correct
36 Correct 290 ms 49860 KB Output is correct
37 Correct 32 ms 21916 KB Output is correct
38 Correct 30 ms 21676 KB Output is correct
39 Correct 137 ms 52184 KB Output is correct
40 Correct 129 ms 51920 KB Output is correct
41 Correct 67 ms 19952 KB Output is correct
42 Correct 69 ms 32608 KB Output is correct
43 Correct 23 ms 19804 KB Output is correct
44 Correct 120 ms 47256 KB Output is correct
45 Correct 46 ms 19800 KB Output is correct
46 Correct 64 ms 19796 KB Output is correct
47 Correct 108 ms 47464 KB Output is correct
48 Correct 111 ms 47456 KB Output is correct
49 Correct 122 ms 24840 KB Output is correct
50 Correct 127 ms 24920 KB Output is correct
51 Correct 275 ms 54008 KB Output is correct
52 Correct 189 ms 53584 KB Output is correct
53 Correct 527 ms 23324 KB Output is correct
54 Correct 209 ms 36740 KB Output is correct
55 Correct 99 ms 20888 KB Output is correct
56 Correct 216 ms 49036 KB Output is correct
57 Correct 339 ms 21348 KB Output is correct
58 Correct 426 ms 21952 KB Output is correct
59 Correct 117 ms 47632 KB Output is correct