답안 #403709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403709 2021-05-13T11:32:24 Z NurstanDuisengaliev Tenis (COCI20_tenis) C++14
50 / 110
90 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]);
		}
		sort (all (v));
		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[mid] < posmx[i]) {
					o = mid;
					l = mid + 1;	
				}
				else r = mid - 1;
			}
			ans[i] += o + 1;
		}
		for (int i = 1; i <= n; i ++) {
			set <int> s;
			for (int k = 1; k <= 3; k ++) {
				int j = X[k][j];
				if (posmx[i] == posmx[j] && i != j) s.in (j);	
			}
			for (auto j : s) {
				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:101:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |     int mid = l + r >> 1;
      |               ~~^~~
tenis.cpp: At global scope:
tenis.cpp:139:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  139 | main () {
      | ^~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 90 ms 460 KB Output is correct
# 결과 실행 시간 메모리 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 90 ms 460 KB Output is correct
5 Incorrect 26 ms 2224 KB Output isn't correct
6 Halted 0 ms 0 KB -