Submission #666563

# Submission time Handle Problem Language Result Execution time Memory
666563 2022-11-29T03:33:43 Z Kaztaev_Alisher Money (IZhO17_money) C++17
0 / 100
1 ms 340 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

ll a[N] , l[N] , r[N] , cnt[N];
pii p[N];
void solve(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		p[i] = {a[i] , i};
	}
	sort(p+1,p+1+n);
	int kal = 0;
	for(int i = 1; i <= n; i++){
		if(p[i].F == p[i-1].F) a[p[i].S] = kal;
		else a[p[i].S] = ++kal;
	}
	for(int i = 1; i <= n; i++){
		cnt[a[i]]++;
		if(a[p[i-1].S] != a[p[i].S]) l[a[p[i].S]] = a[p[i-1].S];
		if(a[p[i+1].S] != a[p[i].S]) r[a[p[i].S]] = a[p[i+1].S];
	}
	ll ans = 0;
	for(int i = n; i >= 1; i--){
		int j = i , b = a[i];
		while(a[j-1] == a[i] && j-1 >= 1) cnt[a[j]]-- , j--;
		while(a[j-1] == l[b] && j-1 >= 1) cnt[a[j]]-- , j-- , b = l[b];
		cnt[a[j]]--;
		if(cnt[a[i]] == 0) r[l[a[j]]] = r[a[i]];
		if(cnt[a[j]] == 0) l[r[a[i]]] = l[a[j]];
		i = j;
		ans++;
	}
	cout << ans << "\n";
}
signed main(){
	ios;
	solve();
	return 0;
}
/*
4
550483 550483 745079 243195
*/
 	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 0 ms 328 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 0 ms 328 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 0 ms 328 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 0 ms 328 KB Output isn't correct
8 Halted 0 ms 0 KB -