Submission #759073

#TimeUsernameProblemLanguageResultExecution timeMemory
759073fanwenStone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
1 ms468 KiB
/** * author : pham van sam * created : 15 June 2023 (Thursday) **/ #include <bits/stdc++.h> using namespace std; using namespace chrono; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it) template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; } template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; } const int MAXN = 2e5 + 5; int N, a[MAXN]; void process(void) { cin >> N; FOR(i, 1, N) cin >> a[i]; map <int, int> cnt; vector <pair <int, int>> events; FOR(i, 1, N) { if(cnt[a[i]] == 0) events.emplace_back(a[i], 1), cnt[a[i]]++; else { int sum = 1; while(!events.empty() && events.back().first != a[i]) { cnt[a[i]] += events.back().second; cnt[events.back().first] -= events.back().second; sum += events.back().second; events.pop_back(); } events.back().second += sum; } } for (auto &[u, tmp] : events) { while(tmp--) cout << u << "\n"; } } signed main() { #define TASK "TASK" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start_time = steady_clock::now(); int test = 1; // cin >> test; for (int i = 1; i <= test; ++i) { process(); // cout << '\n'; } auto end_time = steady_clock::now(); cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); }

Compilation message (stderr)

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