답안 #994829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994829 2024-06-08T07:02:45 Z guagua0407 Editor (BOI15_edi) C++17
15 / 100
51 ms 7020 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=3e5+5;
int e[mxn];

int main() {_
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>e[i];
    }
    vector<pair<int,int>> st;
    set<pair<int,int>> S;
    S.insert({-1,0});
    vector<int> prv(n+1),nxt(n+1),active(n+1);
    for(int i=1;i<=n;i++){
        if(e[i]>=0){
            active[i]=true;
            S.insert({i,e[i]});
        }
        else{
            e[i]=-e[i];
            int pos=lower_bound(all(st),make_pair(e[i],-1))-st.begin();
            int cur=-1;
            if(pos>0){
                cur=st[pos-1].s;
            }
            int cur2=(*S.rbegin()).f;
            if(cur>cur2){
                prv[i]=prv[cur];
            }
            else{
                prv[i]=cur2;
                nxt[cur2]=i;
                while(!st.empty() and st.back().f>=e[i]){
                    st.pop_back();
                }
                st.push_back({e[i],i});
            }
            //cout<<i<<' '<<prv[i]<<'\n';
            active[prv[i]]=!active[prv[i]];
            if(active[prv[i]]){
                S.insert({prv[i],e[prv[i]]});
            }
            else{
                //cout<<"erase"<<'\n';
                S.erase({prv[i],e[prv[i]]});
            }
        }
        //cout<<i<<' '<<prv[i]<<'\n';
        /*cout<<"S"<<'\n';
        for(auto v:S){
            cout<<v.f<<' '<<v.s<<'\n';
        }*/
        cout<<(*S.rbegin()).s<<'\n';
    }
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

edi.cpp: In function 'void setIO(std::string)':
edi.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
edi.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 7020 KB Output is correct
2 Correct 49 ms 6992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 6992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -