Submission #1281266

#TimeUsernameProblemLanguageResultExecution timeMemory
1281266tunademayoStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
249 ms14080 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second const bool Multitest = 0; const int N = 2e5 + 10; map<int, int> cnt; stack<pair<int, int>> t; int a[N], n; void work() { cin >> n; for(int i = 1 ; i <= n ; i++) { cin >> a[i]; } for(int i = 1 ; i <= n ; i++) { //cerr << i << '\n'; if(cnt[a[i]] == 0) { // do nothing here } else { while(true) { pair<int, int> x = t.top(); t.pop(); if(x.fi == a[i]) { break; } else { cnt[a[i]] += x.se; cnt[x.fi] = 0; } } } cnt[a[i]]++; t.push({a[i], cnt[a[i]]}); } int last = n; while(!t.empty()) { pair<int, int> x = t.top(); t.pop(); //cerr << x.fi << ' ' << x.se << '\n'; int tmp = last; last -= x.se; for(int i = last + 1 ; i <= tmp ; i++) a[i] = x.fi; } for(int i = 1 ; i <= n ; i++) cout << a[i] << ' '; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } int q = 1; if(Multitest) cin >> q; while(q--) work(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...