# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229841 | 2020-05-06T19:33:21 Z | Lawliet | Money (IZhO17_money) | C++17 | 4 ms | 384 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; int n; int L[MAXN]; int R[MAXN]; int v[MAXN]; int ord[MAXN]; int firstOcc[MAXN]; void removeSegment(int A, int B) { R[ L[A] ] = R[A]; L[ R[B] ] = L[B]; } int main() { scanf("%d",&n); for(int i = 1 ; i <= n ; i++) { scanf("%d",&v[i]); ord[i] = v[i]; } sort( ord + 1 , ord + n + 1 ); iota( L + 1 , L + n + 1 , 0 ); iota( R + 1 , R + n + 1 , 2 ); for(int i = n ; i > 0 ; i--) firstOcc[ ord[i] ] = i; int ans = 0; int last = n; while( last > 0 ) { ans++; int p = last; int aux = last; while( p > 0 && v[p] == v[last] ) p--; if( p == 0 ) break; int curInd = firstOcc[ v[last] ]; firstOcc[ v[last] ] = curInd + last - p; last = p; for(int i = p ; i > 0 ; i--) { if( v[i] != ord[ L[curInd] ] ) break; last--; curInd = L[curInd]; } removeSegment( last + 1 , aux ); } printf("%d\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |