Submission #403690

# Submission time Handle Problem Language Result Execution time Memory
403690 2021-05-13T11:19:24 Z NurstanDuisengaliev Tenis (COCI20_tenis) C++14
50 / 110
80 ms 2224 KB
// Nurstan Duisengaliev(REALBOY)
// Respa Gold_2022
// IZHO GOLD_2022
// IOI_2022 
/*#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, a[N], b[N];
int pos[N][4], posmx[N]; 
ll ans[N], cnt[4];
int X[4][N];
void Input () {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		int x;
		cin >> x;
		X[1][i] = x;
		pos[x][1] = i;
		posmx[x] = i;
	}
	for (int i = 1; i <= n; i ++) {
		int x;
		cin >> x;
		pos[x][2] = i;
		X[2][i] = x;
		posmx[x] = min (posmx[x], i);
	}
	for (int i = 1; i <= n; i ++) {
		int x;
		cin >> x;
		pos[x][3] = i;
		X[3][i] = x;
		posmx[x] = min (posmx[x], i);
	}
}
void Output () {
	cout << cnt[1] << " " << cnt[2] << " " << cnt[3] << endl;
	for (int i = 1; i <= n; i ++) {
		cout << ans[i] << " ";
	}
	exit (0);
}
void solve () {
	if (n <= 3000) {
		for (int i = 1; i < n; i ++) {
			for (int j = i + 1; j <= n; j ++) {
				int o = mod;
				int ok = min (posmx[i], posmx[j]);	
				for (int t = 1; t <= 3; t ++) {
					if (min (pos[i][t], pos[j][t]) == ok) {
						o = min (o, max (pos[i][t], pos[j][t]));
					}				
				}
				int p = -1;
				for (int t = 1; t <= 3; t ++) {
					if (min (pos[i][t], pos[j][t]) == ok && max (pos[i][t], pos[j][t]) == o) {
						 p = t;
						 break;		
					}
				}
				cnt[p] ++;
				if (pos[i][p] < pos[j][p]) ans[i] ++;
				else ans[j] ++;
			}
		}
	}
	else {
		vector <int> v;
		for (int i = 1; i <= n; i ++) {
			v.pb (posmx[i]);
		}
		for (int i = 1; i <= n; i ++) {
			int l = 0, r = sz (v) - 1, o = -1;
			while (l <= r) {
				int mid = l + r >> 1;
				if (v[i] < posmx[i]) {
					o = i;
					l = mid + 1;	
				}
				else r = mid - 1;
			}
			ans[i] += o + 1;
		}
		for (int i = 1; i <= n; i ++) {
			for (int k = 1; k <= 3; k ++) {
				int j = X[k][posmx[i]];
				if (j != i && posmx[j] == posmx[i]) {
					int o = mod;
					int ok = min (posmx[i], posmx[j]);	
					for (int t = 1; t <= 3; t ++) {
						if (min (pos[i][t], pos[j][t]) == ok) {
							o = min (o, max (pos[i][t], pos[j][t]));
						}				
					}
					int p = -1;
					for (int t = 1; t <= 3; t ++) {
						if (min (pos[i][t], pos[j][t]) == ok && max (pos[i][t], pos[j][t]) == o) {
							 p = t;
							 break;		
						}
					}
					cnt[p] ++;
					if (pos[i][p] < pos[j][p]) ans[i] ++;
					else ans[j] ++;	
				}	
			}
		}
	}
}   	
 
main () {
	boost ();
	Input ();
	solve ();
	Output ();
	return 0;
}

Compilation message

tenis.cpp: In function 'void solve()':
tenis.cpp:100:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |     int mid = l + r >> 1;
      |               ~~^~~
tenis.cpp: At global scope:
tenis.cpp:136:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  136 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 80 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 80 ms 460 KB Output is correct
5 Incorrect 27 ms 2224 KB Output isn't correct
6 Halted 0 ms 0 KB -