Submission #375224

# Submission time Handle Problem Language Result Execution time Memory
375224 2021-03-09T04:42:55 Z NurstanDuisengaliev Po (COCI21_po) C++14
20 / 70
65 ms 12140 KB
// Nurstan Duisengaliev(REALBOY)
// не, не надо меня узнавать 
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/                   
      
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int n;
int a[N];
void compress () {
	set <int> s;
	map <int, int> m;
	for (int i = 1; i <= n; i ++) s.in (a[i]);
	int pos = 1;
	for (auto it : s) {
		m[it] = pos ++;
	}
	for (int i = 1; i <= n; i ++) a[i] = m[a[i]];
}
int last[N];
int d[N * 4];
void build (int v, int l, int r) {
	if (l == r) {
		d[v] = a[l];
		return;
	}
	int mid = l + r >> 1;
	build (v * 2, l, mid);
	build (v * 2 + 1, mid + 1, r);
	d[v] = min (d[v * 2], d[v * 2 + 1]);
}
int get (int v, int l, int r, int nl, int nr) {
	if (nl > r || l > nr) return mod;
	if (nl <= l && r <= nr) return d[v];
	int mid = l + r >> 1;
	return min (get (v * 2, l, mid, nl, nr), get (v * 2 + 1, mid + 1, r, nl, nr));
}
void solve () {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	build (1, 1, n);
	compress (); 
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		if (last[a[i]] == 0) {
			ans ++;
		}
		else {
			if (get (1, 1, n, last[a[i]], i) < a[i]) {
				ans ++;
			}
		}
		last[a[i]] = i;
	}
	cout << ans;
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	                                    
}

Compilation message

Main.cpp: In function 'void build(int, int, int)':
Main.cpp:50:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |  int mid = l + r >> 1;
      |            ~~^~~
Main.cpp: In function 'int get(int, int, int, int, int)':
Main.cpp:58:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |  int mid = l + r >> 1;
      |            ~~^~~
Main.cpp: At global scope:
Main.cpp:83:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   83 | main () {
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 19 ms 1132 KB Output isn't correct
5 Incorrect 29 ms 1900 KB Output isn't correct
6 Correct 63 ms 7276 KB Output is correct
7 Incorrect 65 ms 12140 KB Output isn't correct