답안 #1027439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027439 2024-07-19T06:27:07 Z 정희우(#10953) Sushi (JOI16_sushi) C++17
5 / 100
375 ms 262144 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;

const int MAX_N=400010;

struct Seg
{
    multiset<int> val;
    multiset<int> lazy;
    int push(int v)
    {
        auto it=prev(val.end());
        if(*it<=v)
            return v;
        int v2=*it;
        val.erase(it);
        val.insert(v);
        lazy.insert(v);
        if(lazy.size()>val.size())
            lazy.erase(prev(lazy.end()));
        return v2;
    }
};

int n,q;
int initv[MAX_N];
Seg seg[MAX_N<<2];

void init_(int i,int s,int e)
{
    for(int j=s;j<e;j++)
        seg[i].val.insert(initv[j]);
    if(s+1==e)
        return;
    init_(i<<1,s,(s+e)>>1);
    init_(i<<1|1,(s+e)>>1,e);
}

void update_lazy(Seg &p,Seg &l,Seg &r)
{
    for(auto v : p.lazy)
    {
        int v2=l.push(v);
        r.push(v2);
    }
    p.lazy.clear();
}

int update_(int i,int s,int e,int l,int r,int v)
{
    if(s>=r || e<=l)
        return v;
    if(l<=s && e<=r)
    {
        int v2=seg[i].push(v);
        return v2;
    }
    update_lazy(seg[i],seg[i<<1],seg[i<<1|1]);
    int v1=update_(i<<1,s,(s+e)>>1,l,r,v);
    if(v!=v1)
    {
        auto del=seg[i].val.find(v1);
        seg[i].val.erase(del);
        seg[i].val.insert(v);
    }
    int v2=update_(i<<1|1,(s+e)>>1,e,l,r,v1);
    if(v1!=v2)
    {
        auto del=seg[i].val.find(v2);
        seg[i].val.erase(del);
        seg[i].val.insert(v1);
    }
    return v2;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> q;
    for(int i=0;i<n;i++)
        cin >> initv[i];
    init_(1,0,n);
    while(q--)
    {
        int s,t,p;
        cin >> s >> t >> p;
        if(s<=t)
            p=update_(1,0,n,s-1,t,p);
        else
        {
            p=update_(1,0,n,s-1,n,p);
            p=update_(1,0,n,0,t,p);
        }
        cout << p << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 151892 KB Output is correct
2 Correct 64 ms 151928 KB Output is correct
3 Correct 64 ms 151892 KB Output is correct
4 Correct 63 ms 151928 KB Output is correct
5 Correct 74 ms 152032 KB Output is correct
6 Correct 65 ms 151888 KB Output is correct
7 Correct 68 ms 151896 KB Output is correct
8 Correct 59 ms 151936 KB Output is correct
9 Correct 65 ms 151888 KB Output is correct
10 Correct 82 ms 151980 KB Output is correct
11 Correct 88 ms 152144 KB Output is correct
12 Correct 86 ms 152168 KB Output is correct
13 Correct 95 ms 152144 KB Output is correct
14 Correct 65 ms 152064 KB Output is correct
15 Correct 70 ms 152148 KB Output is correct
16 Correct 61 ms 151824 KB Output is correct
17 Correct 56 ms 150612 KB Output is correct
18 Correct 54 ms 150612 KB Output is correct
19 Correct 53 ms 150740 KB Output is correct
20 Correct 66 ms 150708 KB Output is correct
21 Correct 53 ms 150608 KB Output is correct
22 Correct 55 ms 150612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 375 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 151892 KB Output is correct
2 Correct 64 ms 151928 KB Output is correct
3 Correct 64 ms 151892 KB Output is correct
4 Correct 63 ms 151928 KB Output is correct
5 Correct 74 ms 152032 KB Output is correct
6 Correct 65 ms 151888 KB Output is correct
7 Correct 68 ms 151896 KB Output is correct
8 Correct 59 ms 151936 KB Output is correct
9 Correct 65 ms 151888 KB Output is correct
10 Correct 82 ms 151980 KB Output is correct
11 Correct 88 ms 152144 KB Output is correct
12 Correct 86 ms 152168 KB Output is correct
13 Correct 95 ms 152144 KB Output is correct
14 Correct 65 ms 152064 KB Output is correct
15 Correct 70 ms 152148 KB Output is correct
16 Correct 61 ms 151824 KB Output is correct
17 Correct 56 ms 150612 KB Output is correct
18 Correct 54 ms 150612 KB Output is correct
19 Correct 53 ms 150740 KB Output is correct
20 Correct 66 ms 150708 KB Output is correct
21 Correct 53 ms 150608 KB Output is correct
22 Correct 55 ms 150612 KB Output is correct
23 Runtime error 375 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -