QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#58018#4835. ModeMIT01#RE 4ms6760kbC++4.0kb2022-10-24 10:39:512022-10-24 10:39:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-24 10:39:53]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:6760kb
  • [2022-10-24 10:39:51]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define mod 998244353
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
using namespace std;
const int maxn = 100005;
const int D = 300;
int n;
int a[maxn];
vi pl[maxn];
int ind[maxn]; // index
int ext[D]; // 
int sum[maxn];
int ans[maxn];
void upd(int a, int b) {
    chkmax(ans[a], b);
}
int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int j = 1; j <= n; j++) ans[j] = 0;
        int S = D - 5;
        vi tr;
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tr.pb(a[i]);
        sort(tr.begin(), tr.end());
        for (int i = 1; i <= n; i++)
            a[i] = lower_bound(tr.begin(), tr.end(), a[i]) - tr.begin() + 1;
        for (int i = 1; i <= n; i++) pl[i].clear();
        for (int i = 1; i <= n; i++)
            pl[a[i]].pb(i);
        for (int i = 1; i <= n; i++)
            for (int j = 0; j < pl[i].size(); j++)
                ind[pl[i][j]] = j;
        
        // small small
        for (int j = 0; j < D; j++)
            ext[j] = n + 1;
        auto big = [&](int tp) {
            if (pl[tp].size() >= S)
                return 1;
            return 0;
        };
        auto calans = [&](int tp) {
            // should never call this with big ones!
            if (big(tp)) return 0;
            int res = 0;
            int id = 0;
            for (int j = 0; j < D; j++) {
                int ed = ext[j];
                if (ed > n)
                    break;
                while (id < pl[tp].size() && pl[tp][id] <= ed)
                    id++;
                int nans = pl[tp].size() - id + j;
                chkmax(res, nans);
            }
            return res;
        };
        for (int i = n; i >= 1; i--) {
            int nans = calans(a[i]) + ind[i] + 1;
            upd(a[i], nans);
            for (int j = ind[i]; j < pl[a[i]].size() && j < ind[i] + S; j++)
                chkmin(ext[j - ind[i] + 1], pl[a[i]][j]);
            for (int j = 0; j < D - 1; j++)
                chkmin(ext[j], ext[j + 1]);
        }
        for (int i = 1; i <= n; i++) 
            upd(i, calans(i));
        
        // now do big
        for (int i = 1; i <= n; i++) {
            if (!big(i)) continue;
            for (int j = 1; j <= n; j++)
                sum[j] = (sum[j - 1] + (a[j] == i));
            // i outside; replace with max inner
            for (int b = 1; b <= n; b++) {
                if (big(b)) continue;
                int mpref = 0;
                int mans = 0;
                for (int j = 0; j < pl[b].size(); j++) {
                    int id = pl[b][j];
                    chkmin(mpref, -sum[id] + j);
                    chkmax(mans, sum[id] + j + 1 - mpref);
                }
                upd(i, mans + pl[i].size());
            }

            // b outside
            for (int b = 1; b <= n; b++) {
                if (big(b))
                    continue;
                int mpref = 0;
                int mans = 0;
                for (int j = 0; j < pl[b].size(); j++) {
                    int id = pl[b][j];
                    chkmax(mans, sum[id] - j - mpref);
                    chkmin(mpref, sum[id] - j - 1);
                }
                upd(b, mans + pl[b].size());
            }
        }
        int maxans = 0;
        for (int i = 1; i <= n; i++)
            chkmax(maxans, ans[i]);
        cout << maxans << endl;
        for (int i = 1; i <= n; i++)
            if (ans[i] == maxans)
                printf("%d\n", tr[i - 1]);
    }
    return 0;
}
/*
2
5 10 1
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
*/

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 6168kb

input:

4
5
1 2 3 2 1
5
1 1 3 1 1
6
2 4 2 4 8 8
5
1 2 3 4 5

output:

4
1
5
1
4
2
4
8
2
1
2
3
4
5

result:

ok 14 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 6224kb

input:

10
300
336470888 634074578 642802746 167959139 642802746 481199252 481199252 481199252 167959139 634074578 634074578 336470888 336470888 481199252 642802746 481199252 481199252 167959139 642802746 634074578 167959139 336470888 634074578 642802746 167959139 481199252 167959139 167959139 167959139 481...

output:

80
481199252
634074578
46
153774342
39
846318354
30
937534594
27
698063951
27
419330425
20
603780410
706588687
801036056
20
541308492
19
352404708
16
187061768
428773075

result:

ok 24 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 6760kb

input:

10
300
641009859 804928248 804928248 804928248 804928248 641009859 476927808 641009859 641009859 641009859 75475634 804928248 804928248 641009859 804928248 54748096 75475634 75475634 54748096 75475634 54748096 54748096 476927808 476927808 75475634 476927808 641009859 75475634 476927808 476927808 754...

output:

84
75475634
47
173884819
253838924
593535580
37
119584259
29
66715052
671541499
706982083
25
683509776
23
145885283
637691905
26
968506132
18
277852473
891198181
954696748
18
967045702
19
493331319

result:

ok 27 numbers

Test #4:

score: 0
Accepted
time: 4ms
memory: 6264kb

input:

10
300
923264237 524125987 524125987 524125987 923264237 751244358 374288891 923264237 923264237 923264237 535590429 524125987 374288891 751244358 524125987 923264237 751244358 751244358 923264237 751244358 535590429 535590429 751244358 923264237 751244358 524125987 751244358 923264237 524125987 923...

output:

85
524125987
50
475906689
38
802613215
28
824887911
28
506836893
754648411
23
708438632
731263599
20
210467639
284624362
746100908
806519500
980100704
21
797383894
21
156438550
977566828
17
111777754

result:

ok 27 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 6056kb

input:

10
300
702209411 496813081 561219907 702209411 702209411 561219907 730593611 496813081 702209411 561219907 673102149 702209411 496813081 702209411 673102149 496813081 730593611 496813081 673102149 702209411 673102149 673102149 496813081 496813081 702209411 673102149 561219907 702209411 561219907 561...

output:

81
496813081
53
675266630
38
767363622
32
404396525
27
118275344
195136790
21
422498140
522949042
869477976
887728896
998214353
22
611458649
20
298642883
618165181
853396846
18
510545542
18
41119063
42804963
383659701

result:

ok 29 numbers

Test #6:

score: -100
Runtime Error

input:

6
200000
564718673 564718673 291882089 291882089 412106895 291882089 291882089 412106895 564718673 564718673 412106895 412106895 412106895 564718673 291882089 564718673 412106895 291882089 564718673 291882089 564718673 291882089 291882089 564718673 291882089 412106895 564718673 291882089 564718673 5...

output:


result: