QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#410693 | #6665. 팀 만들기 | bachbeo2007 | 0 | 2ms | 4124kb | C++20 | 3.9kb | 2024-05-14 11:32:51 | 2024-05-14 11:32:52 |
answer
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define se second
#define fi first
const int maxn = 1e5+5;
const int B = 330;
int N,M,Q;
using ll = long long;
using ld = long double;
ll tree[4*maxn],Max[maxn];
#if __cplusplus < 202002L
template <class T> int ssize(const T& a){ return a.size(); }
#endif
template <class T1, class T2> istream& operator>> (istream& in, pair <T1, T2>& a){ in >> a.first >> a.second; return in; }
template <class T> istream& operator>> (istream& in, vector <T>& a){ for (auto &x: a){ in >> x; } return in; }
template<class T, class F>
struct sparse_table{
#ifdef LOCAL
#define ASSERT(x) assert(x)
#else
#define ASSERT(x) 42
#endif
int n;
vector<vector<T>> data;
F TT;
T T_id;
sparse_table(F TT, T T_id): TT(TT), T_id(T_id){ }
sparse_table &operator=(const sparse_table &st){
n = st.n;
data = st.data;
return *this;
}
friend void swap(sparse_table &stl, sparse_table &str){
swap(stl.n, str.n);
swap(stl.data, str.data);
}
// O(n * log(n))
void build(const vector<T> &a){
n = (int)a.size();
if (ssize(data) < 1){
data.resize(1);
}
data[0] = a;
for(auto p = 1, i = 1; p << 1 <= n; p <<= 1, ++ i){
if (ssize(data) <= i){
data.resize(i + 1);
}
data[i].resize(n - (p << 1) + 1);
for(auto j = 0; j < (int)data[i].size(); ++ j) data[i][j] = TT(data[i - 1][j], data[i - 1][j + p]);
}
}
// O(1)
T query(int l, int r) const{
ASSERT(0 <= l && l <= r && r <= n);
if(l == r) return T_id;
int d = __lg(r - l);
return TT(data[d][l], data[d][r - (1 << d)]);
}
};
template<class T, class F>
auto make_sparse_table(F TT, T T_id){
return sparse_table(TT, T_id);
}
template<class T>
auto make_rminq(T inf = numeric_limits<T>::max()){
return sparse_table([&](const T &x, const T &y){ return min(x, y); }, inf);
}
template<class T>
auto make_rmaxq(T minf = numeric_limits<T>::min()){
return sparse_table([&](const T &x, const T &y){ return max(x, y); }, minf);
}
vector<ll> build_teams(vi A1,vi B1,vi A2,vi B2,vi L1,vi R1,vi L2,vi R2) {
N=(int)A1.size();
M=(int)A2.size();
Q=(int)L1.size();
vector<ll> res(Q);
vector<pair<ll,int>> opt(max(N,M));
auto S = make_rmaxq(numeric_limits <pair <ll, int>>::min());
auto C = [&](int i,int j){
return 1LL*(A1[i]+A2[j])*(B1[i]+B2[j]);
};
function<void(int,int,int,int)> dnc = [&](int l,int r,int optl,int optr){
int mid=(l+r)>>1;
for(int i=optl;i<=optr;i++) opt[mid]=max(opt[mid],{C(mid,i),i});
if(l<mid) dnc(l,mid-1,opt[mid].se,optr);
if(mid<r) dnc(mid+1,r,optl,opt[mid].se);
};
auto solve = [&]{
N=(int)A1.size();
M=(int)A2.size();
for(int l=0;l<M;l+=B){
int r=min(l+B,M)-1;
dnc(0,N-1,l,r);
S.build(opt);
for(int i=0;i<Q;i++) if(L2[i]<=l && r<=R2[i]) res[i]=max(res[i],S.query(L1[i],R1[i]+1).fi);
}
};
solve();
swap(A1,A2);
swap(B1,B2);
swap(L1,L2);
swap(R1,R2);
solve();
int N=(int)A1.size();
int M=(int)A2.size();
for(int t=0;t<Q;t++){
vector<int> a,b;
for(int j=L1[t];j<=R1[t];j++){
if(j%B==0 && j+B-1<=R1[t]) j+=B-1;
else a.push_back(j);
}
for(int j=L2[t];j<=R2[t];j++){
if(j%B==0 && j+B-1<=R2[t]) j+=B-1;
else b.push_back(j);
}
function<void(int,int,int,int)> dnc = [&](int l,int r,int optl,int optr){
int mid=(l+r)>>1,opt=-1;
ll val=0;
for(int i=optl;i<=optr;i++){
if(C(a[mid],b[i])>val) opt=i,val=C(a[mid],b[i]);
}
res[t]=max(res[t],val);
if(l<mid) dnc(l,mid-1,opt,optr);
if(mid<r) dnc(mid+1,r,optl,opt);
};
dnc(0,(int)a.size()-1,0,(int)b.size()-1);
}
return res;
}
#undef int
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 4124kb
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: 3892kb
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: 1ms
memory: 3896kb
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: 2ms
memory: 3836kb
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 283rd lines differ - expected: '25648854', found: '25840997'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #47:
score: 0
Runtime Error
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
Runtime Error
Test #65:
score: 0
Runtime Error
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%