답안 #1027520

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

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)
    {
        if(val.empty()) exit(1);
        auto it=prev(val.end());
        if(*it<=v)
            return v;
        int v2=*it;
        val.erase(it);
        if(it==val.end()) exit(1);
        val.insert(v);
        lazy.insert(v);
        if(lazy.size()>val.size())
        {
            if(lazy.empty()) exit(1);
            auto del=prev(lazy.end());
            if(del==lazy.end()) exit(1);
            lazy.erase(del);
        }
        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()) exit(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 46 ms 151888 KB Output is correct
2 Correct 56 ms 151788 KB Output is correct
3 Correct 47 ms 151932 KB Output is correct
4 Correct 47 ms 151900 KB Output is correct
5 Correct 46 ms 151888 KB Output is correct
6 Correct 45 ms 151900 KB Output is correct
7 Correct 39 ms 151888 KB Output is correct
8 Correct 39 ms 151888 KB Output is correct
9 Correct 48 ms 151892 KB Output is correct
10 Correct 46 ms 151896 KB Output is correct
11 Correct 69 ms 151888 KB Output is correct
12 Correct 72 ms 152144 KB Output is correct
13 Correct 69 ms 152048 KB Output is correct
14 Correct 49 ms 151892 KB Output is correct
15 Correct 53 ms 151892 KB Output is correct
16 Correct 38 ms 151900 KB Output is correct
17 Correct 35 ms 150612 KB Output is correct
18 Correct 36 ms 150612 KB Output is correct
19 Correct 35 ms 150624 KB Output is correct
20 Correct 37 ms 150608 KB Output is correct
21 Correct 37 ms 150732 KB Output is correct
22 Correct 36 ms 150664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 369 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 151888 KB Output is correct
2 Correct 56 ms 151788 KB Output is correct
3 Correct 47 ms 151932 KB Output is correct
4 Correct 47 ms 151900 KB Output is correct
5 Correct 46 ms 151888 KB Output is correct
6 Correct 45 ms 151900 KB Output is correct
7 Correct 39 ms 151888 KB Output is correct
8 Correct 39 ms 151888 KB Output is correct
9 Correct 48 ms 151892 KB Output is correct
10 Correct 46 ms 151896 KB Output is correct
11 Correct 69 ms 151888 KB Output is correct
12 Correct 72 ms 152144 KB Output is correct
13 Correct 69 ms 152048 KB Output is correct
14 Correct 49 ms 151892 KB Output is correct
15 Correct 53 ms 151892 KB Output is correct
16 Correct 38 ms 151900 KB Output is correct
17 Correct 35 ms 150612 KB Output is correct
18 Correct 36 ms 150612 KB Output is correct
19 Correct 35 ms 150624 KB Output is correct
20 Correct 37 ms 150608 KB Output is correct
21 Correct 37 ms 150732 KB Output is correct
22 Correct 36 ms 150664 KB Output is correct
23 Runtime error 369 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -