QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665123#5543. The Only ModetemmieRE 960ms32244kbC++172.7kb2024-10-22 04:22:012024-10-22 04:22:01

Judging History

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

  • [2024-10-22 04:22:01]
  • 评测
  • 测评结果:RE
  • 用时:960ms
  • 内存:32244kb
  • [2024-10-22 04:22:01]
  • 提交

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];

struct BinaryIndexTree{
	vector<int> BIT;
	vector<int> backup;

	BinaryIndexTree(int n){
		BIT.assign(n, INF);
		return;
	}

	void update(int pos, int val){
		pos += n;
		backup.push_back(pos);
		for (int i=pos ; i<SZ(BIT) ; i+=i&-i) BIT[i] = min(BIT[i], val);
	}

	int query(int pos){
		pos += n;
		int ret = INF;
		for (int i=pos ; i ; i-=i&-i) ret = min(ret, BIT[i]);
		return ret;
	}

	void reset(){
		for (auto pos : backup) for (int i=pos ; i<SZ(BIT) ; i+=i&-i) BIT[i] = INF;
		backup.clear();
	}
};

/*
1. 先根據一維遞增排序
2. 在根據二維遞減排序
*/

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];

	// 解決三維偏序 [l, r)
	BinaryIndexTree BIT(n*2+5);
	auto CDQ = [&](auto self, int l, int r, vector<vector<int>> &v){
		if (r-l<=1) return 0;
		int mid = (l+r)/2;
		int ans = max(self(self, l, mid, v), self(self, mid, r, v));

		vector<vector<int>> tmp;
		int i, j;
		for (i=l, j=mid ; j<r ; j++){
			while (i<mid && v[i][1]<v[j][1]){
				BIT.update(v[i][2], v[i][3]);
				tmp.push_back(v[i]);
				i++;
			}
			ans = max(ans, v[j][3]-BIT.query(v[j][2]-1));
			tmp.push_back(v[j]);
		}
		BIT.reset();
		while (i<mid){
			tmp.push_back(v[i]);
			i++;
		}
		copy(ALL(tmp), v.begin()+l);
		return ans;
	};

	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(), [](auto a, auto b){
			if (a[0]==b[0]) return a[1]>b[1];
			return a[0]<b[0];
		});
		int ans = CDQ(CDQ, 0, n+1, v);
		cout << ans << " ";
	}
	cout << endl;
	
    return;
}

signed main(){

    fastio;

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

    return 0;
}

详细

Test #1:

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

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

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

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

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

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: 0
Accepted
time: 19ms
memory: 16452kb

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: 676ms
memory: 29800kb

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: 416ms
memory: 25248kb

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: 529ms
memory: 26584kb

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: 625ms
memory: 29036kb

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: 628ms
memory: 29280kb

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: 0
Accepted
time: 787ms
memory: 32244kb

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:

ok single line: '448 100000 52 33 '

Test #13:

score: 0
Accepted
time: 960ms
memory: 31096kb

input:

100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 3 0 0 0 0 0 3 0 0 0 0 0...

output:

100000 0 0 11 

result:

ok single line: '100000 0 0 11 '

Test #14:

score: -100
Runtime Error

input:

100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:


result: