답안 #711489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711489 2023-03-17T05:43:47 Z devvops Izbori (COCI22_izbori) C++17
25 / 110
2711 ms 5176 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
using namespace std;
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end() 
#define speed ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
const int mod = (int) 1e9 + 7;
const int N = (int) 2e5 + 100;
const int bruh = 500;

ll a[N], tree[N], n, k;
map<int, int> cnt;

void upd(int idx){
	for(int i = idx; i < N; i += i & -i){
		tree[i] += 1;
	}
}

ll get(int x){
	ll ans = 0;
	for (int i = x; i > 0; i -= i & -i) {
         ans += 1LL * tree[i];
    }
    return ans;
}

signed main(){
   	speed;
   	cin >> n;
   	for(int i = 1; i <= n; i++){
   		cin >> a[i];
   		cnt[a[i]]++;
   	} 
   	ll ans = 0;
   	for(auto i : cnt){
   		if(i.S > bruh){
   			memset(tree, 0, sizeof(tree));
	   		vector<int> v;
	   		for(int j = 1; j <= n; j++){
	   			if(a[j] == i.F) v.pb(1);
	   			else v.pb(-1);
	   		}
	   		int s = 0;
	   		upd(n + 1);
	   		for(int j = 0; j < n; j++){
	   			s += v[j];
	   			if(s < 0){
	   				upd(abs(s));
	   				ans += 1LL * (get(n) - get(abs(s)));
	   			}
	   			else{
	   				upd(s + (n + 1));
	   				ans += get(n) - get(0);
	   				ans += 1LL * (get(n + s) - get(n));
	   			}
	   		}
   		}
   	}
   	for(int i = 1; i <= n; i++){
   		map<int, int> cnt1;
   		int lst = -1, lstA = -1;
   		for(int j = i; j <= n; j++){
   			if((j - i + 1) > 2 * bruh) break;
   			if(a[j] == lstA) lst++;
   			++cnt1[a[j]];
   			int sz = (j - i) + 1;
   			if(lst > (sz / 2) && cnt[lstA] <= bruh) ans += 1LL;
   			else if(cnt1[a[j]] > (sz / 2) && cnt[a[j]] <= bruh){
   				ans += 1LL;
   				lst = cnt1[a[j]];
   				lstA = a[j];
   			}
   		}
   	}
   	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 70 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 39 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 37 ms 340 KB Output is correct
12 Correct 37 ms 340 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Correct 37 ms 340 KB Output is correct
15 Correct 43 ms 336 KB Output is correct
16 Correct 38 ms 340 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1689 ms 4492 KB Output is correct
2 Correct 2300 ms 4904 KB Output is correct
3 Correct 1338 ms 3528 KB Output is correct
4 Correct 2523 ms 4996 KB Output is correct
5 Correct 2466 ms 5092 KB Output is correct
6 Incorrect 2711 ms 5176 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 70 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 39 ms 340 KB Output is correct
10 Correct 39 ms 340 KB Output is correct
11 Correct 37 ms 340 KB Output is correct
12 Correct 37 ms 340 KB Output is correct
13 Correct 39 ms 340 KB Output is correct
14 Correct 37 ms 340 KB Output is correct
15 Correct 43 ms 336 KB Output is correct
16 Correct 38 ms 340 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
18 Correct 1689 ms 4492 KB Output is correct
19 Correct 2300 ms 4904 KB Output is correct
20 Correct 1338 ms 3528 KB Output is correct
21 Correct 2523 ms 4996 KB Output is correct
22 Correct 2466 ms 5092 KB Output is correct
23 Incorrect 2711 ms 5176 KB Output isn't correct
24 Halted 0 ms 0 KB -