Submission #994790

#TimeUsernameProblemLanguageResultExecution timeMemory
994790guagua0407Editor (BOI15_edi)C++17
35 / 100
33 ms3420 KiB
//#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]; //cout<<e[i]<<' '; } //cout<<'\n'; if(n<=5000){ vector<bool> active(n+1); vector<int> prv(n+1); set<pair<int,int>> S; S.insert({-1,0}); for(int i=1;i<=n;i++){ if(e[i]>=0){ active[i]=true; S.insert({i,e[i]}); } else{ active[i]=true; int x; for(int j=i-1;j>=0;j--){ if(active[j] and (e[j]>=0 or e[j]>e[i])){ x=j; break; } } //cout<<i<<' '<<x<<'\n'; prv[i]=x; while(e[x]<0){ active[x]=!active[x]; x=prv[x]; } active[x]=!active[x]; if(active[x]){ S.insert({x,e[x]}); } else{ S.erase({x,e[x]}); } } cout<<(*S.rbegin()).s<<'\n'; } return 0; } vector<int> ans; ans.push_back(0); for(int i=1;i<=n;i++){ if(e[i]>=0) ans.push_back(e[i]); else ans.pop_back(); cout<<ans.back()<<'\n'; } return 0; } //maybe its multiset not set //yeeorz //laborz

Compilation message (stderr)

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
edi.cpp: In function 'int main()':
edi.cpp:52:40: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |                     active[x]=!active[x];
      |                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...