QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#664284#5543. The Only ModetemmieTL 1570ms52236kbC++172.9kb2024-10-21 20:00:472024-10-21 20:00:47

Judging History

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

  • [2024-10-21 20:00:47]
  • 评测
  • 测评结果:TL
  • 用时:1570ms
  • 内存:52236kb
  • [2024-10-21 20:00:47]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#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 = 3e5+100;
const int INF = 2e18;
const int P = 1e5+10;

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

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

gp_hash_table<int, gp_hash_table<int, int, custom_hash>, custom_hash> 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 40664kb

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: 0ms
memory: 40708kb

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: 40708kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 3ms
memory: 40704kb

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: 40736kb

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 68ms
memory: 41452kb

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: 0
Accepted
time: 1570ms
memory: 52020kb

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:

89925 49888 75725 38162 

result:

ok single line: '89925 49888 75725 38162 '

Test #8:

score: 0
Accepted
time: 1073ms
memory: 49792kb

input:

64937
1 1 0 2 1 1 3 1 1 1 2 0 3 1 1 2 1 2 2 1 0 2 1 1 1 1 1 0 3 1 0 2 1 0 0 0 0 2 1 2 1 2 2 1 2 3 2 1 2 1 3 0 1 3 0 0 1 3 1 2 2 2 0 3 3 1 3 0 3 3 2 0 1 1 2 0 3 3 3 2 1 0 1 0 1 3 0 0 2 1 0 3 3 1 2 3 2 1 1 0 0 3 1 1 2 1 0 2 1 0 0 1 1 3 0 1 2 1 3 2 0 3 1 2 1 2 0 0 0 1 1 2 3 3 2 1 1 1 2 1 3 1 2 2 2 0 1 ...

output:

64937 61901 51387 63870 

result:

ok single line: '64937 61901 51387 63870 '

Test #9:

score: 0
Accepted
time: 1230ms
memory: 49584kb

input:

73423
1 2 2 0 0 0 0 2 1 2 1 2 1 3 1 3 3 0 1 2 2 0 0 0 3 2 1 1 0 3 0 2 1 3 1 1 2 3 0 1 2 1 0 0 0 3 3 0 3 2 3 3 1 1 3 2 0 0 0 3 2 0 0 2 3 3 3 3 3 2 3 2 2 2 3 3 0 1 1 2 2 2 1 2 2 1 1 2 1 2 2 3 0 3 0 2 2 2 1 2 1 1 2 3 0 1 3 2 0 3 3 3 0 2 2 2 3 1 0 1 0 1 1 3 0 0 2 1 1 3 1 3 3 2 0 2 2 1 1 0 1 0 2 3 1 2 3 ...

output:

36577 18616 60210 73423 

result:

ok single line: '36577 18616 60210 73423 '

Test #10:

score: 0
Accepted
time: 1400ms
memory: 52236kb

input:

82517
2 1 1 0 2 0 3 1 3 1 3 3 2 2 3 0 3 2 2 0 2 1 0 2 2 3 2 0 1 0 1 2 2 1 1 1 3 2 2 0 1 0 0 3 3 1 1 0 3 1 3 1 2 3 3 3 3 3 2 1 3 1 3 0 2 0 2 0 2 2 2 2 2 1 2 1 3 3 2 3 2 3 0 2 0 1 0 0 3 2 1 1 0 1 2 1 1 0 1 3 1 3 3 2 2 3 0 2 1 3 2 1 0 1 2 3 2 2 3 3 1 0 2 0 3 2 3 0 1 2 0 3 3 0 2 1 1 3 3 2 2 0 2 2 1 1 2 ...

output:

50863 68187 40176 82517 

result:

ok single line: '50863 68187 40176 82517 '

Test #11:

score: 0
Accepted
time: 1358ms
memory: 51088kb

input:

79392
0 2 2 2 0 3 2 3 1 1 1 0 0 3 1 3 3 0 2 2 0 0 0 2 1 0 2 2 2 1 2 3 2 0 3 3 3 2 0 1 0 1 1 1 0 1 0 1 0 2 3 3 0 1 2 3 0 1 0 1 0 1 2 2 1 3 0 0 1 3 1 2 2 1 0 0 2 1 0 0 2 2 3 1 3 0 3 2 0 0 0 0 3 3 0 0 2 2 0 2 0 2 3 1 0 2 2 1 2 2 0 3 3 3 2 1 3 1 1 1 1 2 0 0 1 1 1 0 1 1 1 3 3 0 2 3 1 1 0 1 2 3 1 3 3 0 0 ...

output:

68113 34911 26794 79392 

result:

ok single line: '68113 34911 26794 79392 '

Test #12:

score: -100
Time Limit Exceeded

input:

100000
2 0 0 1 0 2 3 3 0 2 1 2 0 2 0 3 0 0 2 0 1 1 0 1 1 1 1 0 2 2 0 1 0 1 0 0 0 3 1 0 3 0 1 1 1 3 1 0 1 3 1 1 1 0 1 3 0 1 1 0 1 3 0 0 0 0 0 0 0 1 0 0 1 3 1 3 0 1 0 0 2 1 1 2 2 0 3 3 2 1 1 0 0 1 1 2 0 1 2 0 3 3 1 1 1 0 3 3 0 1 3 0 1 0 2 1 3 3 2 3 2 0 2 3 0 2 2 2 0 1 0 0 1 0 2 1 1 1 2 1 2 1 1 0 3 1 1...

output:

448 100000 52 33 

result: