QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664272#5543. The Only ModetemmieTL 127ms66296kbC++172.2kb2024-10-21 19:56:512024-10-21 19:56:51

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 19:56:51]
  • 评测
  • 测评结果:TL
  • 用时:127ms
  • 内存:66296kb
  • [2024-10-21 19:56:51]
  • 提交

answer


#include <bits/stdc++.h>
#define int long long
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define fastio ios::sync_with_stdio(0), cin.tie(0);
using namespace std;

#ifdef LOCAL
#define cout cout << "\033[0;32m"
#define cerr cerr << "\033[0;31m"
#define endl "\n" << "\033[0m"
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,sse4,popcnt")
#define endl "\n"
#endif

const int MAX_N = 5e5+10;
const int INF = 2e18;
const int P = 1e5+10;

// declare
int n;
vector<int> v;
vector<int> d[4][4];
map<int, map<int, int>> BIT;

void update(int pos1, int pos2, int val){
	pos1 += P, pos2 += P;
	for (int i=pos1 ; i<MAX_N ; i+=i&-i){
		for (int j=pos2 ; j<MAX_N ; j+=j&-j){
			BIT[i][j] = BIT[i].find(j)!=BIT[i].end() ? min(BIT[i][j], val) : val;
		}
	}
}

int query(int pos1, int pos2){
	pos1 += P, pos2 += P;
	int ret = INF;
	for (int i=pos1 ; i ; i-=i&-i){
		if (BIT.find(i)==BIT.end()) continue;
		for (int j=pos2 ; j ; j-=j&-j){
			if (BIT[i].find(j)==BIT[i].end()) continue;
			ret = min(ret, BIT[i][j]);
		}
	}
	return ret;
}

void solve1(){

	// init
	for (int i=0 ; i<4 ; i++){
		for (int j=0 ; j<4 ; j++){
			d[i][j].resize(MAX_N);
		}
	}

	// input
	cin >> n;
	v.resize(n);
	for (int i=0 ; i<n ; i++) cin >> v[i];

	// process
	for (int i=0 ; i<n ; i++) for (int j=0 ; j<4 ; j++) for (int k=0 ; k<4 ; k++){
		if (v[i]==j) d[j][k][i]++;
		if (v[i]==k) d[j][k][i]--;
	}
	for (int i=1 ; i<n ; i++) for (int j=0 ; j<4 ; j++) for (int k=0 ; k<4 ; k++) d[j][k][i] += d[j][k][i-1];

	for (int i=0 ; i<4 ; i++){
		vector<vector<int>> v(n);
		v.push_back({0, 0, 0, -1});
		for (int j=0 ; j<n ; j++){
			for (int k=0 ; k<4 ; k++){
				if (i==k) continue;
				v[j].push_back(d[i][k][j]);
			}
			v[j].push_back(j);
		}

		sort(v.begin(), v.end());
		vector<vector<int>> buffer;
		int ans = 0;
		for (int i=0 ; i<n+1 ; i++){
			if (i && v[i][0]!=v[i-1][0]){
				for (auto x : buffer){
					update(x[1], x[2], x[3]);
				}
				buffer.clear();
			}
			ans = max(ans, v[i][3]-query(v[i][1]-1, v[i][2]-1));
			buffer.push_back(v[i]);
		}

		cout << ans << " ";

		BIT.clear();
	}
	cout << endl;
	
    return;
}

signed main(){

    fastio;

    int t = 1;
    while (t--){
        solve1();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 65536kb

input:

7
1 2 2 0 3 0 3

output:

4 1 5 3 

result:

ok single line: '4 1 5 3 '

Test #2:

score: 0
Accepted
time: 8ms
memory: 65708kb

input:

12
2 0 1 0 2 1 1 0 2 3 3 3

output:

4 9 1 9 

result:

ok single line: '4 9 1 9 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 65656kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 0ms
memory: 65660kb

input:

12
3 0 2 2 1 0 2 1 3 3 2 3

output:

1 5 11 8 

result:

ok single line: '1 5 11 8 '

Test #5:

score: 0
Accepted
time: 4ms
memory: 65600kb

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 127ms
memory: 66296kb

input:

4207
3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...

output:

2330 1520 4207 1359 

result:

ok single line: '2330 1520 4207 1359 '

Test #7:

score: -100
Time Limit Exceeded

input:

89925
0 0 0 3 0 3 0 2 3 2 3 1 0 0 0 2 2 1 3 3 0 0 1 0 0 3 0 1 0 0 1 1 0 0 1 2 1 3 1 2 1 2 2 1 0 2 2 3 0 0 1 0 2 3 2 3 0 0 1 0 0 1 2 1 3 0 0 0 2 1 1 0 1 3 2 2 0 0 2 3 2 3 3 1 3 3 0 2 0 2 2 0 2 1 3 0 1 1 0 0 1 0 3 1 2 2 2 0 2 0 2 3 2 0 0 2 3 3 1 0 1 2 2 2 1 2 0 0 3 2 3 0 1 1 3 3 0 0 0 3 0 2 0 0 2 3 1 ...

output:


result: