QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#665026#5543. The Only ModetemmieTL 108ms16396kbC++173.6kb2024-10-22 00:47:352024-10-22 00:47:35

Judging History

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

  • [2024-10-22 00:47:35]
  • 评测
  • 测评结果:TL
  • 用时:108ms
  • 内存:16396kb
  • [2024-10-22 00:47:35]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#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 = 2e5+100;
const int INF = 2e9;
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);
    }
};


// fast IO
// 6f8879
inline char readchar(){
    static char buffer[BUFSIZ], * now = buffer + BUFSIZ, * end = buffer + BUFSIZ;
    if (now == end)
    {
        if (end < buffer + BUFSIZ)
            return EOF;
        end = (buffer + fread(buffer, 1, BUFSIZ, stdin));
        now = buffer;
    }
    return *now++;
}
inline int nextint(){
    int x = 0, c = readchar(), neg = false;
    while(('0' > c || c > '9') && c!='-' && c!=EOF) c = readchar();
    if(c == '-') neg = true, c = readchar();
    while('0' <= c && c <= '9') x = (x<<3) + (x<<1) + (c^'0'), c = readchar();
    if(neg) x = -x;
    return x; // returns 0 if EOF
}

// gp_hash_table<int, gp_hash_table<int, int, custom_hash>, custom_hash> BIT;
unordered_map<int, unordered_map<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
	n = nextint();
	v.resize(n);
	for (int i=0 ; i<n ; i++) v[i] = nextint();

	// 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: 15784kb

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: 5ms
memory: 15772kb

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

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

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

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 108ms
memory: 16396kb

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: