Submission #924033

#TimeUsernameProblemLanguageResultExecution timeMemory
924033SunbaeStone Arranging 2 (JOI23_ho_t1)C++17
35 / 100
36 ms8580 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int A[N], m;
vector<int>C;
int pos(int x){return lower_bound(C.begin(), C.end(), x) - C.begin();}
int B[N];
vector<int> V[N];
bool cmp(int x, int y){return V[x].front() < V[y].front();}
signed main(){
	int n; scanf("%d", &n);
	for(int i = 0; i<n; ++i) scanf("%d", A+i), C.push_back(A[i]);
	sort(C.begin(), C.end());
	C.resize(unique(C.begin(), C.end()) - C.begin());
	m = C.size();
	for(int i = 0; i<n; ++i) A[i] = pos(A[i]);
	for(int i = 0; i<n; ++i) V[A[i]].push_back(i);
	for(int i = 0; i<m; ++i) B[i] = i;
	sort(B, B+m, cmp);
	int Right = -1;
	for(int i = 0; i<m; ++i){
		int x = B[i];
		int l = max(Right+1, V[x].front());
		int r = V[x].back();
		if(l > r) continue;
		for(int j = l; j<=r; ++j) printf("%d\n", C[x]);
		Right = max(Right, r);
	}
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  for(int i = 0; i<n; ++i) scanf("%d", A+i), C.push_back(A[i]);
      |                           ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...