답안 #970561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970561 2024-04-26T17:38:25 Z rahidilbayramli 말 (IOI15_horses) C++17
0 / 100
358 ms 524288 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;
int x[sz], y[sz], n;
pii segtree[4*sz];
set<pii>st;
int m(int 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()
{
    int res = 1, lst = n+1;
    for(auto u : st)
    {
        res = max(res, findans(1, 1, n, -u.f, lst-1).s);
        res *= u.s;
        if(res >= mod)
            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[]) {
    for(int i = 1; i <= N; i++)
    {
        x[i] = X[i-1];
        y[i] = Y[i-1];
        if(i == 1 || x[i] >= 2)
            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(int, int)':
horses.cpp:25:18: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   25 | int m(int x, int y)
      |              ~~~~^
horses.cpp:22:12: note: shadowed declaration is here
   22 | int x[sz], y[sz], n;
      |            ^
horses.cpp:25:11: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   25 | int m(int x, int y)
      |       ~~~~^
horses.cpp:22:5: note: shadowed declaration is here
   22 | int x[sz], y[sz], n;
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 358 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -