QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410895#6665. 팀 만들기tuanlinh1230 6ms3936kbC++203.2kb2024-05-14 16:35:072024-05-14 16:35:08

Judging History

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

  • [2024-05-14 16:35:08]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:3936kb
  • [2024-05-14 16:35:07]
  • 提交

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=1, 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++) a.pb({a1[i], b1[i]});
        for (ll i=0; i<m; i++) b.pb({a2[i], b2[i]});
        RMQ S(calc(b, a));
        for (ll i=0; 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++) a.pb({a2[i], b2[i]});
        for (ll i=0; i<n; i++) b.pb({a1[i], b1[i]});
        RMQ S(calc(b, a));
        for (ll i=0; 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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
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
24262630
25260576
25444230
25944610
26027379
25944610
21794500
25502475
19748843
25944610
25269202
25294500
24084151
25944610
25944610
25923420
25745327
24134670
21842574

result:

wrong answer 2nd lines differ - expected: '24221652', found: '24262630'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #47:

score: 0
Time Limit Exceeded

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:

Unauthorized output

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #65:

score: 0
Time Limit Exceeded

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:

Unauthorized output

result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%