답안 #1027505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027505 2024-07-19T07:09:05 Z 정희우(#10953) Sushi (JOI16_sushi) C++17
5 / 100
388 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);
        if(it==val.end())
            while(1);
        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);
    int v2=update_(i<<1|1,(s+e)>>1,e,l,r,v1);
    if(v!=v2)
    {
        auto del=seg[i].val.find(v2);
        if(del==seg[i].val.end())
            while(1);
        seg[i].val.erase(del);
        seg[i].val.insert(v);
    }
    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 49 ms 151900 KB Output is correct
2 Correct 46 ms 151888 KB Output is correct
3 Correct 44 ms 151888 KB Output is correct
4 Correct 47 ms 151888 KB Output is correct
5 Correct 49 ms 151900 KB Output is correct
6 Correct 51 ms 151892 KB Output is correct
7 Correct 40 ms 151888 KB Output is correct
8 Correct 40 ms 151896 KB Output is correct
9 Correct 48 ms 151900 KB Output is correct
10 Correct 49 ms 151892 KB Output is correct
11 Correct 70 ms 152148 KB Output is correct
12 Correct 80 ms 152044 KB Output is correct
13 Correct 64 ms 152148 KB Output is correct
14 Correct 45 ms 151896 KB Output is correct
15 Correct 48 ms 152052 KB Output is correct
16 Correct 42 ms 151888 KB Output is correct
17 Correct 35 ms 150620 KB Output is correct
18 Correct 33 ms 150872 KB Output is correct
19 Correct 34 ms 150620 KB Output is correct
20 Correct 35 ms 150744 KB Output is correct
21 Correct 35 ms 150556 KB Output is correct
22 Correct 36 ms 150612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 388 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 151900 KB Output is correct
2 Correct 46 ms 151888 KB Output is correct
3 Correct 44 ms 151888 KB Output is correct
4 Correct 47 ms 151888 KB Output is correct
5 Correct 49 ms 151900 KB Output is correct
6 Correct 51 ms 151892 KB Output is correct
7 Correct 40 ms 151888 KB Output is correct
8 Correct 40 ms 151896 KB Output is correct
9 Correct 48 ms 151900 KB Output is correct
10 Correct 49 ms 151892 KB Output is correct
11 Correct 70 ms 152148 KB Output is correct
12 Correct 80 ms 152044 KB Output is correct
13 Correct 64 ms 152148 KB Output is correct
14 Correct 45 ms 151896 KB Output is correct
15 Correct 48 ms 152052 KB Output is correct
16 Correct 42 ms 151888 KB Output is correct
17 Correct 35 ms 150620 KB Output is correct
18 Correct 33 ms 150872 KB Output is correct
19 Correct 34 ms 150620 KB Output is correct
20 Correct 35 ms 150744 KB Output is correct
21 Correct 35 ms 150556 KB Output is correct
22 Correct 36 ms 150612 KB Output is correct
23 Runtime error 388 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -