Submission #1284051

#TimeUsernameProblemLanguageResultExecution timeMemory
1284051Bui_Quoc_CuongStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
148 ms15860 KiB
#include <bits/stdc++.h>
using namespace std;
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define all(v) (v).begin(), (v).end()
#define sz(a) (int)a.size()
#define FOR(i, a, b) for (int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for (int i = a; i >= (int)b; i--) 
#define fi first
#define se second
template <class T1, class T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;}return false;}
template <class T1, class T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;}return false;}

const int N = 2e5 + 5;

int n;
int a[N];
map <int, int> last_val;
map <int, vector <int>> pos_val;
int ans[N];

void solve()
{
	cin >> n;
	stack <pair <int, int>> st;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if(last_val[a[i]])
		{
			int cnt = 1;
			while(!st.empty() && st.top().first != a[i])
			{
				cnt+= st.top().second;
				last_val[st.top().first] = false;
				st.pop();
			}
			st.push({a[i], cnt});
		}  else
		{
			st.push({a[i], 1});
			last_val[a[i]] = true;
		}
	}
	vector <pair <int, int>> res;
	while(!st.empty()) 
	{
		res.push_back(st.top());
		st.pop();
	}
	reverse(all(res));
	for(auto x : res)
	{
		for(int j = 1; j <= x.second; j++) cout << x.first << "\n";
	}
}	

signed main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define koa "kieuoanh"
    if(fopen(koa".inp", "r")) 
    {
        freopen(koa".inp", "r", stdin); 
        freopen(koa".out", "w", stdout);
    }

    solve();

    return 0;
}

Compilation message (stderr)

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