QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639049#4929. Longest Unfriendly Subsequenceyjs_0 13ms11404kbC++142.9kb2024-10-13 17:45:442024-10-13 17:45:44

Judging History

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

  • [2024-10-13 17:45:44]
  • 评测
  • 测评结果:0
  • 用时:13ms
  • 内存:11404kb
  • [2024-10-13 17:45:44]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
//#define int ll
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mid (l+r>>1)
#define rg register
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define prq_mn(x) priority_queue<x, vector<x>, greater<x> >
#define prq_mx(x) priority_queue<x, vector<x>, less<x> >
#define Clear(x, y) memset(x, y, sizeof(x))
#define fi first
#define se second
#define DEBUG printf("Debug on line %d\n", __LINE__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 2e5 + 114514;
const int INF = 0x3f3f3f3f;
const int inf = 0xcfcfcfcf;

template <typename T> bool updmax(T& a, T b) {return a<b ? a=b, 1 : 0;}
template <typename T> bool updmin(T& a, T b) {return a>b ? a=b, 1 : 0;}

inline int read(){
	int n=0, f=1; char ch = getchar();
	for(; !isdigit(ch); ch=getchar()) if(ch == '-') f=-1;
	for(; isdigit(ch); ch=getchar()) n=n*10+ch-'0';
	return n*f;
}

int T;
int n, m;
int a[N];
vector<int> vec; 
int mx[N], mxk[N], smx[N], smxk[N];
int lst[N], tp;

void addlst(int x){
	for(int i=tp; i>=0; i--){
		if(lst[i] == x){ // 找到相同的 
			for(int j=i; j<tp; j++) lst[j] = lst[j+1];
			lst[tp] = x;
			return;
		}
	}
	
	// 没找到相同的 
	lst[++tp] = x;
} 

void upd1(int y, int val, int k){
//	printf("upd1(%d, %d, %d, %d, %d)\n", x, y, val, k);
	if(val > mx[y]){
		smx[y] = mx[y];
		smxk[y] = mxk[y];
		mx[y] = val;
		mxk[y] = k;
	} else if(k != mxk[y] && val > smx[y]){
		smx[y] = val;
		smxk[y] = k;
	}
}

void upd(int y1, int y2, int val, int ii){
//	printf("upd(%d, %d, %d, %d, %d, %d)\n", x1, y1, x2, y2, val, ii);
	if(!val || mxk[y2] != a[ii]) upd1(y1, mx[y2]+val, val ? y2 : mxk[y2]);
	if(!val || smxk[y2] != a[ii]) upd1(y1, smx[y2]+val, val ? y2 : smxk[y2]);
}

signed main(){
	T = read();
	while(T--){
		vec.clear();
		
		n = read();
		for(int i=1; i<=n; i++){
			a[i] = read();
			vec.pb(a[i]);
		}
		
		sort(vec.begin(), vec.end());
		vec.erase(unique(vec.begin(), vec.end()), vec.end());
		m = vec.size();
		for(int i=1; i<=n; i++){
			a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin() + 1;
//			printf("a[%d] = %d\n", i, a[i]);
		}
		
		Clear(mx, inf); Clear(mxk, inf); Clear(smx, inf); Clear(smxk, inf);
		Clear(lst, 0);
		tp = 0;
		mx[0] = 0; mxk[0] = 0;
		for(int i=1; i<=n; i++){
			for(int jj=tp; jj>=0; jj--){
				int j = lst[jj];
				if(a[i] != j) upd(a[i], j, 1, i);
			}
			addlst(a[i]);
			
//			for(int j=0; j<=m; j++){
//				printf("mx[%d][%d] = %d\n", i, j, mx[j]);
//				printf("mxk[%d][%d] = %d\n", i, j, mxk[j]);
//				printf("smx[%d][%d] = %d\n", i, j, smx[j]);
//				printf("smxk[%d][%d] = %d\n", i, j, smxk[j]);
//			}
		}
		
		int ans = inf;
		for(int j=0; j<=m; j++){
			ans = max(ans, mx[j]);
		}
		printf("%d\n", ans);
	}
}

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 3
Accepted
time: 11ms
memory: 11092kb

input:

1
200000
259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 2...

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Time Limit Exceeded

input:

1
200000
1521 1638 11981 18811 20091 22081 30494 31501 42139 42282 48197 55520 57632 69584 81745 85026 90303 91482 92176 98507 108061 108743 111257 121226 127217 127449 137116 163474 169192 175764 181243 185402 191244 198775 202845 212156 217723 220058 223478 224205 227614 228398 230425 232567 24480...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #15:

score: 6
Accepted
time: 3ms
memory: 10112kb

input:

3
5
1 2 1 2 1
7
1 2 3 2 1 2 3
8
1 10 10 1 1 100 100 1

output:

2
6
4

result:

ok 3 lines

Test #16:

score: 0
Time Limit Exceeded

input:

28653
6
372076545 832760265 372076545 644300403 644300403 644300403
8
540046638 375129642 863244619 863244619 375129642 540046638 540046638 540046638
6
142783193 508154499 871683432 71368434 871683432 871683432
8
760894385 984189193 760894385 323542350 984189193 760894385 323542350 323542350
6
84093...

output:

3
4
4
6
4
4
3
4
5
4
5
4
2
4
5
5
4
3
5
5
4
4
4
5
6
4
2
3
4
3
2
3
4
3
8
4
5
5
4
6
4
5
5
5
4
6
6
4
3
3
7
5
3
7
3
4
6
6
5
4
3
3
6
3
6
4
3
4
4
7
3
4
5
4
5
1
3
6
4
4
4
4
2
3
4
2
5
3
4
2
2
3
4
3
6
3
5
3
4
5
3
3
4
4
5
3
5
4
4
6
5
6
6
4
5
4
5
5
3
4
3
4
4
2
4
4
6
5
4
3
3
2
3
5
4
5
3
3
4
7
4
5
5
2
5
2
4
4
5
4
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 8
Accepted
time: 2ms
memory: 10940kb

input:

1
500
537076440 691668159 871942500 537076440 537076440 691668159 871942500 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 871942500 537076440 691668159 871942500 537076440 537076440 6916...

output:

361

result:

ok single line: '361'

Test #20:

score: 8
Accepted
time: 1ms
memory: 11096kb

input:

1
500
584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 101442702 335815880 335815880 584142119 584142119 101442702 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 1014...

output:

394

result:

ok single line: '394'

Test #21:

score: 0
Wrong Answer
time: 2ms
memory: 10232kb

input:

1
500
296341737 806184542 989331127 989331127 296341737 806184542 455929030 296341737 806184542 806184542 806184542 989331127 296341737 806184542 989331127 296341737 806184542 989331127 296341737 806184542 989331127 296341737 806184542 806184542 989331127 296341737 296341737 296341737 806184542 9893...

output:

321

result:

wrong answer 1st lines differ - expected: '339', found: '321'

Subtask #4:

score: 0
Wrong Answer

Test #79:

score: 10
Accepted
time: 13ms
memory: 11404kb

input:

1
200000
1 3 3 2 2 3 3 1 2 3 1 1 3 3 3 2 1 1 2 3 2 1 3 3 3 1 2 2 1 3 1 2 1 2 3 2 3 3 2 2 3 2 3 2 3 1 1 1 1 1 3 1 3 2 3 3 3 3 1 3 2 1 3 2 3 2 3 1 1 1 1 3 3 2 3 2 1 2 2 3 2 3 2 2 2 2 2 2 3 2 1 2 2 1 1 3 2 1 2 1 1 3 3 3 2 1 2 2 2 1 3 3 2 3 2 1 3 3 2 2 1 3 1 3 2 1 2 3 2 1 2 3 2 2 3 2 1 2 1 1 1 1 1 1 1 3...

output:

66691

result:

ok single line: '66691'

Test #80:

score: 10
Accepted
time: 9ms
memory: 10856kb

input:

1
200000
2 2 3 3 3 2 1 2 1 1 1 3 3 2 3 3 1 3 2 3 3 3 2 1 2 2 2 2 1 1 2 2 1 3 1 3 1 3 3 1 2 1 1 2 1 1 2 1 1 1 1 2 2 1 3 2 3 3 2 3 2 3 1 1 1 1 2 3 1 2 1 1 2 3 2 3 3 2 1 2 1 1 3 3 3 1 2 3 1 3 1 3 1 1 2 1 3 2 1 1 3 2 1 1 3 2 3 2 3 2 1 3 2 2 2 1 2 2 1 3 3 1 3 1 2 3 1 1 2 2 2 1 3 1 1 3 3 2 3 2 1 3 1 1 1 3...

output:

66403

result:

ok single line: '66403'

Test #81:

score: 0
Wrong Answer
time: 11ms
memory: 11356kb

input:

1
200000
1 2 3 3 1 2 3 3 1 2 3 1 1 2 3 1 2 3 1 2 2 3 1 2 2 3 3 3 1 2 3 3 1 2 3 3 1 1 2 2 3 3 1 2 3 3 1 1 2 3 1 2 2 3 3 1 2 3 1 1 1 1 2 3 3 1 2 2 3 1 1 1 2 2 3 3 1 1 1 2 2 3 1 1 2 3 3 1 1 2 3 1 2 3 1 2 3 3 1 1 2 3 1 1 1 1 2 3 1 2 3 3 1 2 2 2 2 2 3 1 1 2 3 1 2 2 3 1 2 3 3 1 2 2 3 1 2 3 1 1 1 2 2 3 1 2...

output:

100295

result:

wrong answer 1st lines differ - expected: '113082', found: '100295'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%