QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410879#6665. 팀 만들기tuanlinh1230 1131ms8908kbC++203.3kb2024-05-14 16:23:372024-05-15 12:10:39

Judging History

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

  • [2024-05-15 12:10:39]
  • 管理员手动重测该提交记录
  • 测评结果:0
  • 用时:1131ms
  • 内存:8908kb
  • [2024-05-14 16:23:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

const ll maxn=100005, s=300, inf=5e18;

// returns a vector where the ith element is the maximum value when a[i] is paired with one of the elements of b
vector <ll> calc(const vector <pll> &a, const vector <pll> &b)
{
    ll n=sz(a), m=sz(b);
    vector <ll> ans(n, 0);
    auto cost=[&](ll i, ll j) {return (a[i].fi+b[j].fi)*(a[i].se+b[j].se);};
    function <void(ll, ll, ll, ll)> DnC=[&](ll l, ll r, ll optl, ll optr)
    {
        if (l>r) return;
        ll mid=(l+r)/2, opt=optl;
        for (ll i=optl; i<=optr; i++)
            if (ans[mid]<cost(mid, i))
                opt=i, ans[mid]=cost(mid, i);
        DnC(l, mid-1, opt, optr);
        DnC(mid+1, r, optl, opt);
    }; DnC(0, n-1, 0, m-1);
    return ans;
}

struct RMQ
{
    ll n;
    vector <ll> num;
    vector <vector <ll>> sp;

    RMQ(vector <ll> num): num(num)
    {
        n=sz(num);
        sp=vector <vector <ll>>(__lg(n)+1, vector <ll> (n));
        for (ll i=0; i<n; i++) sp[0][i]=num[i];
        for (ll i=1; i<=__lg(n); i++)
            for (ll j=0; j+(1<<i)<=n; j++)
                sp[i][j]=max(sp[i-1][j], sp[i-1][j+(1<<i-1)]);
    }

    ll query(ll l, ll r)
    {
        l--, r--;
        ll j=__lg(r-l+1);
        return max(sp[j][l], sp[j][r-(1<<j)+1]);
    }
};

vector<long long> build_teams(vector<int> a1, vector<int> b1, vector<int> a2, vector<int> b2, 
vector<int> l1, vector<int> r1, vector<int> l2, vector<int> r2) 
{
    ll n=sz(a1), m=sz(a2), q=sz(l1);
    vector <ll> answer(q, 0);
    for (ll i=0; i<q; i++)
    {
        ll bl1=l1[i]/s, br1=r1[i]/s, bl2=l2[i]/s, br2=r2[i]/s;
        vector <pll> a, b;
        if (bl1==br1) for (ll j=l1[i]; j<=r1[i]; j++) a.pb({a1[j], b1[j]});
        else 
        {
            for (ll j=l1[i]; j<(bl1+1)*s; j++) a.pb({a1[j], b1[j]});
            for (ll j=br1*s; j<=r1[i]; j++) a.pb({a1[j], b1[j]});
        }
        if (bl2==br2) for (ll j=l2[i]; j<=r2[i]; j++) b.pb({a2[j], b2[j]});
        else
        {
            for (ll j=l2[i]; j<(bl2+1)*s; j++) b.pb({a2[j], b2[j]});
            for (ll j=br2*s; j<=r2[i]; j++) b.pb({a2[j], b2[j]});
        }
        vector <ll> res1=calc(a, b), res2=calc(b, a);
        for (ll j:res1) answer[i]=max(answer[i], j);
        for (ll j:res2) answer[i]=max(answer[i], j);
    }
    for (ll bl=0; bl+s<=n; bl+=s)
    {
        vector <pll> a, b;
        for (ll i=bl; i<bl+s && i<n; i++) a.pb({a1[i], b1[i]});
        for (ll i=0; i<m; i++) b.pb({a2[i], b2[i]});
        vector <ll> num=calc(b, a);
        RMQ S(num);
        for (ll i=1; i<=q; i++)
            if (l1[i]<=bl && bl+s-1<=r1[i])
                answer[i]=max(answer[i], S.query(l2[i], r2[i]));
    }
    for (ll bl=0; bl+s<=m; bl+=s)
    {
        vector <pll> a, b;
        for (ll i=bl; i<bl+s && i<m; i++) a.pb({a2[i], b2[i]});
        for (ll i=0; i<n; i++) b.pb({a1[i], b1[i]});
        vector <ll> num=calc(b, a);
        RMQ S(num);
        for (ll i=1; i<=q; i++)
            if (l2[i]<=bl && bl+s-1<=r2[i])
                answer[i]=max(answer[i], S.query(l1[i], r1[i]));
    }
    return answer;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 3936kb

input:

500 499
7 4997
13 4988
20 4983
28 4969
44 4963
49 4922
54 4919
58 4897
71 4893
72 4886
85 4883
102 4879
107 4876
113 4868
128 4845
133 4839
135 4831
138 4821
140 4809
156 4793
178 4780
181 4776
190 4760
196 4756
203 4752
209 4736
225 4728
228 4723
232 4720
235 4709
253 4676
258 4660
260 4645
266 463...

output:

25745327
24221652
25260576
25444230
25944610
26027379
25944610
21794500
25502475
19748843
25944610
25269202
25294500
24084151
25944610
25944610
25923420
25745327
24097815
21842574

result:

ok 20 lines

Test #2:

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

input:

500 499
3 4994
6 4989
12 4978
20 4972
22 4965
32 4949
48 4914
52 4893
56 4875
62 4867
66 4860
80 4840
98 4828
106 4814
108 4788
127 4785
142 4783
177 4775
181 4770
182 4766
191 4764
201 4757
205 4753
235 4743
298 4740
300 4725
326 4720
346 4714
350 4709
373 4703
379 4680
390 4674
391 4643
393 4640
3...

output:

22404249
24625440
24983847
24994621
26178282
25385964
25028495
18972628
24778368
24808000
25212965
24604640
23302608
24979302
22241460
25385964
24155109
26178282
25137864
25619090

result:

ok 20 lines

Test #3:

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

input:

500 499
3 4988
4 4967
8 4953
10 4942
11 4936
13 4930
20 4927
40 4904
43 4897
61 4892
65 4852
70 4849
74 4815
78 4812
90 4801
91 4792
107 4783
116 4781
121 4770
123 4747
125 4738
129 4706
132 4700
134 4698
139 4684
145 4680
148 4667
155 4665
164 4652
181 4651
188 4649
191 4648
199 4646
202 4628
209 4...

output:

25458244
17507070
23722057
23685867
24493896
26156980
21925946
26222616
25564880
25172184
24611064
17491437
25418853
25931580
25669456
25144644
26156980
25931580
17224980
25581918

result:

ok 20 lines

Test #4:

score: -5
Wrong Answer
time: 8ms
memory: 3912kb

input:

500 499
22 5000
23 4994
33 4971
34 4960
35 4949
36 4943
37 4930
66 4891
112 4879
118 4863
132 4859
136 4854
152 4851
153 4848
154 4845
164 4842
180 4814
184 4801
197 4798
211 4794
214 4789
221 4773
226 4770
250 4768
256 4760
265 4728
267 4727
272 4718
288 4693
313 4691
318 4683
340 4676
352 4662
355...

output:

25267216
25648854
24950190
25648854
25648854
25192470
25648854
25267216
25267216
25022088
25648854
25267216
24968784
24378216
25648854
25840997
25648854
25648854
25648854
25822235
25648854
24947710
25822235
25822235
25822235
25267216
25648854
25022088
25509360
25840997
25648854
25648854
25648854
252...

result:

wrong answer 70th lines differ - expected: '25587610', found: '25612565'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 1131ms
memory: 8664kb

input:

200 100000
335635 996427627
4368692 990235584
10335314 971208588
11639195 971143844
23801483 970115479
31489602 959110431
31544396 956821351
48348198 954187112
48509739 953684848
51173262 952420589
53207608 941523603
62582103 940608015
65545228 932323862
73708623 932037283
80559453 929148992
9033280...

output:

905205543896920220
1059275121529352398
1059275121529352398
1059275121529352398
979409542016948625
1059275121529352398
1059275121529352398
1059275121529352398
1059275121529352398
972560707248716820
1011171607306697480
1043073690916288143
1059275121529352398
1059275121529352398
1059275121529352398
976...

result:

wrong answer 1st lines differ - expected: '993958698780308505', found: '905205543896920220'

Subtask #4:

score: 0
Wrong Answer

Test #65:

score: 35
Accepted
time: 244ms
memory: 8908kb

input:

200 100000
2904660 993940483
16886371 993289642
17317405 990982034
18403947 976774733
18849359 973351068
19183185 970254940
19306003 966229683
21192298 964806508
23734314 964320708
23888967 955733824
27113148 951453312
37031360 944529530
39266197 937051115
40090929 928931574
59651306 922916360
69712...

output:

1016308928382908236
998776313884663776
1004320593689684616
933903565326321240
978390546778315197
1039650121469876757
987990669763090785
1042865155786780773
1051441808434023804
971637196420999780
1065416677472286269
1012697889755804003
905550355710151258
1060082943529963956
1013827359119034944
104933...

result:

ok 100000 lines

Test #66:

score: -35
Wrong Answer
time: 635ms
memory: 8880kb

input:

100000 200
1940 999994594
10389 999989035
28503 999981667
30870 999980471
42230 999972276
52125 999971275
53379 999956174
55518 999955459
64639 999955412
65268 999904054
67682 999885452
77130 999857307
93130 999831628
108438 999823346
126919 999823214
134181 999822103
143172 999812542
147613 9998090...

output:

996096623179059236
969910467114454830
924034362173985265
1009298970998067699
970694474737666780
962248662711411726
972319486384869810
934783008648683200
951800917340303219
706802138404465088
1007389400623713408
937052239542096915
956323407319144750
1006081611944400924
956985211239863942
900383066251...

result:

wrong answer 1st lines differ - expected: '996157338533370640', found: '996096623179059236'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%