QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639026 | #4929. Longest Unfriendly Subsequence | yjs_ | 3 | 20ms | 11220kb | C++14 | 2.9kb | 2024-10-13 17:41:29 | 2024-10-13 17:41:32 |
Judging History
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, (n+10)*sizeof(int))
#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>=max(tp, 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>=max(tp, 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: 3
Accepted
Test #1:
score: 3
Accepted
time: 6ms
memory: 10132kb
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: 3
Accepted
time: 20ms
memory: 11072kb
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:
198858
result:
ok single line: '198858'
Test #3:
score: 3
Accepted
time: 10ms
memory: 11220kb
input:
1 200000 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 222796328 2...
output:
3
result:
ok single line: '3'
Test #4:
score: 3
Accepted
time: 10ms
memory: 11116kb
input:
1 200000 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 760101 7601...
output:
575
result:
ok single line: '575'
Test #5:
score: 3
Accepted
time: 20ms
memory: 11052kb
input:
1 200000 22617 30507 37038 41687 43064 43064 49267 55626 59203 73739 82817 99920 109370 115622 115622 121135 121135 129717 129717 133074 133133 133133 142580 142580 142580 154213 154816 154816 161169 180270 186425 208068 213631 237721 252184 261468 266076 271129 271129 272992 278768 279170 299395 31...
output:
136202
result:
ok single line: '136202'
Test #6:
score: 3
Accepted
time: 7ms
memory: 10404kb
input:
5 24325 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 558278563 55...
output:
3 143 605 169 1
result:
ok 5 lines
Test #7:
score: 3
Accepted
time: 16ms
memory: 10460kb
input:
5 86417 13696 27186 31482 38856 51078 60129 60129 63547 67673 87520 97892 99326 118061 118645 146408 154082 166604 178823 201607 241484 250276 265112 265112 265112 266533 267321 312070 312070 314782 320641 321224 325817 328085 351487 365110 374487 382485 385081 393245 400245 419177 421858 423028 426...
output:
68280 264 2 26943 5
result:
ok 5 lines
Test #8:
score: 3
Accepted
time: 10ms
memory: 9004kb
input:
5 2977 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112394126 112...
output:
5 2 186 403 3
result:
ok 5 lines
Test #9:
score: 3
Accepted
time: 15ms
memory: 10324kb
input:
20 11481 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 2249526 224...
output:
84 1 6616 5 157 3 4 173 2652 64 73 2669 97 22009 20 36 4231 33 1 8816
result:
ok 20 lines
Test #10:
score: 3
Accepted
time: 8ms
memory: 10160kb
input:
100 1273 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 276188388 2...
output:
4 3 2906 3 2038 1262 2671 102 1 3 771 34 58 30 2 300 21 106 1 1 72 1 22 1123 5 547 5182 2 87 85 4 1370 158 74 2 1098 61 1027 11 82 1 377 2 715 5 52 67 3 472 158 1 58 6836 75 712 2 59 2 4 52 16 5 2 78 273 4281 36 1178 60 16 2 22 421 5 11 11 33 5 74 3 2 3 3 1770 5 2172 5 67 5 4 480 514 5 57 461 39 5 3...
result:
ok 100 lines
Test #11:
score: 3
Accepted
time: 12ms
memory: 10020kb
input:
1000 309 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 4317803 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 49219507 134343195 241438227 241438227 241438227 241438227 241...
output:
19 4 52 20 182 1 4 91 4 84 2 121 18 14 1 22 9 10 2 7 150 9 76 9 5 5 10 17 46 2 25 17 4 40 397 13 157 12 5 5 78 6 99 3 287 20 86 26 16 8 24 329 28 11 4 9 4 4 10 182 35 20 117 41 1 5 54 1 713 111 8 5 4 2 18 3 38 72 8 1 17 3 2 9 14 25 5 3 2 15 140 6 7 173 81 5 30 2 5 2 8 52 3 16 58 2 146 8 31 4 458 2 1...
result:
ok 1000 lines
Test #12:
score: 3
Accepted
time: 11ms
memory: 8004kb
input:
10000 13 116636133 116636133 206284888 206284888 565476781 812400365 812400365 961195858 961195858 961195858 961195858 961195858 961195858 2 8191780 8191780 43 95905577 95905577 95905577 95905577 95905577 95905577 487815159 487815159 602877460 602877460 602877460 602877460 602877460 602877460 602877...
output:
5 1 8 2 3 10 13 1 2 2 4 2 2 1 5 1 21 3 1 11 13 1 9 1 2 1 2 3 1 8 6 3 26 2 2 3 26 1 15 2 8 1 1 11 9 2 6 2 2 2 10 6 3 8 5 3 2 6 6 16 5 5 2 11 6 1 3 1 1 2 32 5 9 1 1 11 8 3 1 1 3 3 1 3 26 1 43 1 10 1 8 2 1 1 3 21 30 5 19 1 5 16 2 18 1 1 1 13 3 3 4 3 23 3 3 2 1 10 1 13 2 1 14 4 1 3 7 1 1 1 1 2 14 3 5 5 ...
result:
ok 10000 lines
Test #13:
score: 3
Accepted
time: 13ms
memory: 10040kb
input:
30000 18 77687359 77687359 77687359 77687359 77687359 77687359 77687359 77687359 264737334 264737334 264737334 264737334 423170703 423170703 423170703 423170703 423170703 423170703 3 426699491 894864848 895502688 23 329836738 329836738 329836738 329836738 329836738 329836738 329836738 329836738 3298...
output:
3 3 4 2 1 4 3 1 5 1 2 2 2 5 2 3 2 1 10 1 2 3 1 4 1 2 1 4 5 2 4 3 3 1 1 1 4 5 1 2 1 6 4 1 10 10 24 1 15 1 1 1 2 1 8 7 1 1 2 3 4 4 4 2 4 3 5 3 5 2 5 15 2 1 1 2 1 1 1 3 5 4 11 1 2 2 7 4 2 1 9 1 1 1 3 1 3 2 1 5 1 2 10 3 4 1 5 8 1 3 7 4 1 1 1 1 2 4 5 3 3 1 1 1 2 2 3 3 5 5 2 4 11 2 2 1 1 5 2 1 1 2 5 5 4 4...
result:
ok 30000 lines
Test #14:
score: 3
Accepted
time: 1ms
memory: 10132kb
input:
1 10000 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:
1
result:
ok single line: '1'
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 1ms
memory: 7884kb
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 3 2
result:
wrong answer 2nd lines differ - expected: '6', found: '3'
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 1ms
memory: 7992kb
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:
292
result:
wrong answer 1st lines differ - expected: '361', found: '292'
Subtask #4:
score: 0
Wrong Answer
Test #79:
score: 0
Wrong Answer
time: 6ms
memory: 10088kb
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:
33230
result:
wrong answer 1st lines differ - expected: '66691', found: '33230'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%