답안 #998027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998027 2024-06-13T08:26:53 Z guagua0407 Editor (BOI15_edi) C++17
15 / 100
90 ms 30804 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 prv[mxn][20];
int last[mxn];
int e[mxn];
int lev[mxn];
int cur=0;

int main() {_
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>e[i];
        e[i]*=-1;
        lev[i]=max(0,e[i]);
        if(e[i]>0){
            int x=i-1;
            for(int j=19;j>=0;j--){
                if(lev[prv[x][j]]>=lev[i]){
                    x=prv[x][j];
                }
            }
            x=prv[x][0];
            if(lev[i-1]<lev[i]){
                x=i-1;
            }
            last[i]=x;
            x=last[x];
            for(int j=0;j<20;j++){
                prv[i][j]=x;
                x=prv[x][j];
            }
        }
        else{
            last[i]=cur;
        }
        int ans=i;
        for(int j=19;j>=0;j--){
            if(lev[prv[ans][j]]>0){
                ans=prv[ans][j];
            }
        }
        if(lev[ans]>0) ans=prv[ans][0];
        cout<<-e[ans]<<'\n';
        cur=ans;
    }
    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 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 30804 KB Output is correct
2 Correct 90 ms 30644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 13644 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 -