Submission #941391

#TimeUsernameProblemLanguageResultExecution timeMemory
941391shoryu386Stone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long main(){ int n; cin >> n; int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x]; stack< tuple<int, int, int> > stk; unordered_multiset<int> valInStk; for (int x = 0; x < n; x++){ if (valInStk.find(arr[x]) != valInStk.end()){ int stopLoc = -1; while (!stk.empty()){ if ( get<2>(stk.top()) == arr[x]){ stopLoc = get<0>(stk.top()); valInStk.erase(valInStk.find(get<2>(stk.top()))); stk.pop(); break; } else{ valInStk.erase(valInStk.find(get<2>(stk.top()))); stk.pop(); } } assert(stopLoc != -1); stk.push({stopLoc, x, arr[x]}); } else{ stk.push({x, x, arr[x]}); valInStk.insert(arr[x]); } } int res[n]; memset(res, -1, sizeof(res)); while (!stk.empty()){ auto tup = stk.top(); for (int y = get<0>(tup); y <= get<1>(tup); y++){ res[y] = get<2>(tup); } stk.pop(); } for (int x = 0; x < n; x++) cout << res[x] << '\n'; }

Compilation message (stderr)

Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...