QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87946 | #5242. Płótno [B] | anhduc2701 | 0 | 2486ms | 76764kb | C++23 | 6.3kb | 2023-03-14 21:33:47 | 2023-03-14 21:33:49 |
Judging History
answer
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) (int)(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;
vector<pair<int,int>>st[maxn];
int lazy[maxn];
int s[2][maxn];
ll ans[maxn];
vector<pair<int,pair<int,int>>>p[maxn];
vector<pair<int,int>>mer(vector<pair<int,int>>&A,vector<pair<int,int>>&B){
int l1=0;
int l2=0;
vector<pair<int,int>>p;
while(len(p)<min(k+1,len(A)+len(B))){
int ok=0;
if(l1<len(A) && l2<len(B)){
if(A[l1].fi==B[l2].fi){
p.pb({A[l1].fi,A[l1].se+B[l2].se});
l1++;
l2++;
ok=1;
}
else if(A[l1].fi<B[l2].fi){
p.pb(A[l1]);
l1++;
ok=1;
}
else{
p.pb(B[l2]);
l2++;
ok=1;
}
}
else if(l2==len(B) && l1<len(A)){
p.pb(A[l1]);
l1++;
}
else if(l1==len(A) && l2<len(B)){
p.pb(B[l2]);
l2++;
}
if(l1==len(A) && l2==len(B)){
break;
}
}
return p;
}
void build(int id,int l,int r){
if(l==r){
st[id].pb({0,1});
return;
}
int mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
st[id]=mer(st[id*2],st[id*2+1]);
}
void push(int id){
if(lazy[id]!=0){
for(int i=0;i<st[id*2].size();i++){
st[id*2][i].fi+=lazy[id];
}
for(int i=0;i<st[id*2+1].size();i++){
st[id*2+1][i].fi+=lazy[id];
}
lazy[id*2]+=lazy[id];
lazy[id*2+1]+=lazy[id];
lazy[id]=0;
}
}
void update(int id,int l,int r,int u,int v,int val){
if(l==u && v==r){
lazy[id]+=val;
for(int i=0;i<st[id].size();i++){
st[id][i].fi+=val;
}
return;
}
int mid=(l+r)/2;
push(id);
if(v<=mid){
update(id*2,l,mid,u,v,val);
}
else if(u>mid){
update(id*2+1,mid+1,r,u,v,val);
}
else{
update(id*2,l,mid,u,mid,val);
update(id*2+1,mid+1,r,mid+1,v,val);
}
st[id]=mer(st[id*2],st[id*2+1]);
}
vector<pair<int,int>>get(int id,int l,int r,int u,int v){
vector<pair<int,int>>res;
if(l==u && v==r){
return st[id];
}
int mid=(l+r)/2;
push(id);
if(v<=mid){
return get(id*2,l,mid,u,v);
}
else if(mid<u){
return get(id*2+1,mid+1,r,u,v);
}
else{
vector<pair<int,int>>A=get(id*2,l,mid,u,mid);
vector<pair<int,int>>B=get(id*2+1,mid+1,r,mid+1,v);
return mer(A,B);
}
}
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
//freopen(task".inp" , "r" , stdin);
//freopen(task".out" , "w" , stdout);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>s[0][i];
}
for(int i=1;i<=n;i++){
cin>>s[1][i];
}
s[0][0]=s[0][n];
s[1][0]=s[1][n];
n*=2;
for(int i=1;i<=n/2;i++){
// a<b<c<d
int a=s[0][i];
int b=s[1][i];
int aa=s[0][i-1];
int bb=s[1][i-1];
if(a>b){
swap(a,b);
swap(aa,bb);
}
// a<b nam giua
// bb<a<b<aa
if((bb<a && b<aa)){
cout<<"Case 1: "<<i<<"\n";
int min1=min(aa,bb);
int ma1=min(aa,bb);
p[1].pb({1,{a,b-1}});
p[bb+1].pb({-1,{a,b-1}});
p[bb+1].pb({1,{a,aa-1}});
p[a+1].pb({-1,{a,aa-1}});
p[a+1].pb({1,{b,n}});
p[b+1].pb({-1,{b,n}});
}
// aa<a<b<bb
else if(aa<a && b<bb){
cout<<"Case 2: "<<i<<"\n";
p[aa+1].pb({1,{a,bb-1}});
p[b+1].pb({-1,{a,bb-1}});
}
//a<b<bb<aa
else if(b<bb && bb<aa){
cout<<"Case 3: "<<i<<"\n";
int d=min(aa,bb);
p[1].pb({1,{a,bb-1}});
p[b+1].pb({-1,{a,bb-1}});
}
// a<b<aa<bb
else if(b<aa && aa<bb){
// cout<<"Casemiro:"<<i<<"\n";
p[1].pb({1,{a,aa-1}});
p[b].pb({-1,{a,aa-1}});
p[b].pb({1,{b,bb-1}});
p[b+1].pb({-1,{b,bb-1}});
}
// aa<bb<a<b
else if(aa<bb && bb<a && a<b){
// cout<<"Case4: "<<i<<"\n";
int d=max(aa,bb);
p[aa+1].pb({1,{a,b-1}});
p[bb+1].pb({-1,{a,b-1}});
p[bb+1].pb({1,{a,n}});
p[a+1].pb({-1,{a,n}});
p[a+1].pb({1,{b,n}});
p[b+1].pb({-1,{a,n}});
}
// bb<aa<a<b
else if(bb<aa&& aa<a && a<b){
// cout<<"caseee: "<<i<<"\n";
p[aa+1].pb({1,{a,n}});
p[b+1].pb({-1,{a,n}});
}
// a<aa<b<bb
else if(a< aa && aa<b && b<bb){
// cout<<"Case5: "<<i<<"\n";
p[1].pb({1,{a,aa-1}});
p[a+1].pb({-1,{a,aa-1}});
p[a+1].pb({1,{b,bb-1}});
p[b+1].pb({-1,{b,bb-1}});
}
// a<aa<bb<b
else if(a< aa && aa<bb && bb<b){
// cout<<"Case6: "<<i<<"\n";
p[1].pb({1,{a,aa-1}});
p[a+1].pb({-1,{a,aa-1}});
p[bb+1].pb({1,{b,n}});
p[b+1].pb({-1,{b,n}});
}
// a<bb<b<aa
else if(a<bb && bb<b && b<aa){
// cout<<"Case7: "<<i<<"\n";
p[1].pb({1,{a,b-1}});
p[a+1].pb({-1,{a,b-1}});
p[bb+1].pb({1,{b,n}});
p[b+1].pb({-1,{b,n}});
}
// aa<a<bb<b
else if(aa<a && a<bb && bb<b){
// cout<<"Case8: "<<i<<"\n";
p[aa+1].pb({1,{a,b-1}});
p[a+1].pb({-1,{a,b-1}});
p[bb+1].pb({1,{b,n}});
p[b+1].pb({-1,{b,n}});
}
// bb<a<aa<b
else if(bb<a && a<aa && aa<b){
// cout<<"Case9: "<<i<<"\n";
p[1].pb({1,{a,aa-1}});
p[a+1].pb({-1,{a,aa-1}});
p[a+1].pb({1,{b,n}});
p[b+1].pb({-1,{b,n}});
}
}
build(1,1,n);
for(int i=1;i<=n;i++){
for(auto v:p[i]){
// cout<<i<<" "<<v.se.fi<<" "<<v.se.se<<" "<<v.fi<<"\n";
update(1,1,n,v.se.fi,v.se.se,v.fi);
}
vector<pair<int,int>>q=get(1,1,n,i,n);
for(auto v:q){
// cout<<i<<" "<<v.fi<<" "<<v.se<<"\n";
ans[v.fi]+=(ll)(v.se);
}
}
for(int i=1;i<=k;i++){
if(i==1){
cout<<ans[0]+ans[1]<<" ";
}
else cout<<ans[i]<<" ";
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 50288kb
input:
10 1 6 18 4 17 1 8 7 13 5 10 2 20 3 11 15 12 19 16 14 9
output:
Case 3: 3 Case 2: 6 Case 2: 8 Case 1: 10 47
result:
wrong answer 1st lines differ - expected: '58', found: 'Case 3: 3'
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 8ms
memory: 50204kb
input:
2 4 1 2 4 3
output:
Case 2: 2 10 0 0 0
result:
wrong answer 1st lines differ - expected: '10 0 0 0', found: 'Case 2: 2'
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 22ms
memory: 50308kb
input:
500 10 917 838 302 172 930 427 28 597 459 846 477 474 4 764 33 821 250 204 653 309 142 916 795 928 387 956 810 433 973 609 226 556 547 540 860 847 535 147 768 619 448 52 551 131 294 892 423 241 363 117 566 285 702 230 6 624 358 802 672 641 384 639 911 251 823 750 587 865 751 890 604 317 473 606 998 ...
output:
Case 2: 2 Case 3: 4 Case 3: 9 Case 3: 12 Case 1: 17 Case 1: 22 Case 2: 27 Case 2: 28 Case 2: 30 Case 1: 32 Case 2: 33 Case 3: 37 Case 3: 38 Case 1: 40 Case 3: 44 Case 1: 47 Case 3: 48 Case 3: 54 Case 1: 58 Case 2: 60 Case 3: 64 Case 3: 67 Case 1: 76 Case 2: 79 Case 3: 84 Case 1: 87 Case 1: 98 Case 2...
result:
wrong answer 1st lines differ - expected: '1781 1446 1564 1298 1500 1585 1516 1761 1659 1513', found: 'Case 2: 2'
Subtask #4:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 1243ms
memory: 72368kb
input:
100000 1 96176 27939 172191 74850 13479 117742 8634 21501 87321 149607 137789 134176 152101 180468 138683 166438 7726 31523 144362 26825 69995 74641 50479 72511 84577 185202 80203 157069 16984 58419 129101 172394 1618 195274 94592 35724 186278 93215 35874 2038 125395 20762 171892 53749 678 174925 13...
output:
Case 1: 3 Case 1: 11 Case 3: 12 Case 2: 15 Case 1: 18 Case 2: 25 Case 2: 30 Case 1: 41 Case 1: 42 Case 1: 44 Case 1: 47 Case 2: 52 Case 1: 58 Case 3: 60 Case 2: 61 Case 2: 70 Case 3: 71 Case 1: 73 Case 1: 76 Case 3: 80 Case 1: 83 Case 3: 86 Case 1: 88 Case 2: 90 Case 3: 93 Case 1: 98 Case 1: 99 Case...
result:
wrong answer 1st lines differ - expected: '335745', found: 'Case 1: 3'
Subtask #5:
score: 0
Wrong Answer
Test #61:
score: 0
Wrong Answer
time: 198ms
memory: 54684kb
input:
20000 1 8260 23162 19083 31764 38686 5100 19437 18310 29053 16504 25374 30501 7543 30973 12153 5191 24580 3044 23328 33054 31229 26909 10407 33096 22917 26256 5677 13524 16383 36303 27681 25325 2346 30364 23195 6239 24636 2591 24756 17408 20987 35844 10387 25215 22822 31666 39853 30752 36965 8863 35...
output:
Case 3: 1 Case 3: 6 Case 3: 15 Case 2: 20 Case 3: 22 Case 1: 30 Case 2: 31 Case 2: 35 Case 1: 38 Case 3: 43 Case 2: 44 Case 3: 45 Case 2: 48 Case 2: 61 Case 2: 63 Case 3: 68 Case 1: 70 Case 2: 74 Case 3: 76 Case 3: 77 Case 2: 79 Case 3: 85 Case 1: 86 Case 1: 88 Case 1: 95 Case 1: 97 Case 1: 99 Case ...
result:
wrong answer 1st lines differ - expected: '58709', found: 'Case 3: 1'
Subtask #6:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 408ms
memory: 55660kb
input:
20000 10 37122 3130 15044 10634 29395 31698 29227 38486 30743 16224 36762 21225 34434 7049 5922 29646 17043 2684 30346 11095 29406 16909 26412 8343 29837 8721 28099 8734 7717 29088 6414 27191 13096 8463 34156 23605 31577 4853 39185 24977 28983 34919 10330 1303 23468 11457 17442 28837 16603 31324 424...
output:
Case 3: 2 Case 2: 3 Case 1: 9 Case 3: 14 Case 1: 19 Case 2: 22 Case 1: 24 Case 1: 27 Case 3: 31 Case 3: 34 Case 2: 36 Case 1: 38 Case 2: 40 Case 2: 46 Case 2: 49 Case 2: 53 Case 2: 57 Case 2: 60 Case 3: 62 Case 3: 70 Case 2: 87 Case 3: 93 Case 3: 97 Case 3: 100 Case 1: 107 Case 1: 111 Case 2: 114 Ca...
result:
wrong answer 1st lines differ - expected: '62119 52465 66066 51757 46662 46349 56343 50160 45653 51054', found: 'Case 3: 2'
Subtask #7:
score: 0
Wrong Answer
Test #96:
score: 0
Wrong Answer
time: 1337ms
memory: 72180kb
input:
100000 1 184488 199575 61547 186158 115443 82615 177342 64604 124208 4012 152444 113522 105138 104715 64740 152490 175932 130353 169948 187430 30884 108488 12761 28267 180529 162418 98945 127768 181574 92995 74927 17992 52128 144406 91892 165442 133627 58061 70318 156100 159695 56046 14083 192791 76...
output:
Case 2: 6 Case 2: 9 Case 2: 12 Case 1: 18 Case 3: 21 Case 1: 22 Case 3: 23 Case 2: 26 Case 1: 27 Case 1: 30 Case 1: 39 Case 2: 42 Case 2: 49 Case 2: 53 Case 3: 55 Case 2: 59 Case 3: 60 Case 1: 62 Case 1: 67 Case 3: 71 Case 2: 74 Case 3: 88 Case 1: 96 Case 1: 97 Case 3: 103 Case 1: 105 Case 2: 113 Ca...
result:
wrong answer 1st lines differ - expected: '493945', found: 'Case 2: 6'
Subtask #8:
score: 0
Wrong Answer
Test #109:
score: 0
Wrong Answer
time: 2419ms
memory: 76764kb
input:
100000 10 13763 82869 153448 151170 185611 191283 101826 196257 150421 49313 96588 32246 110056 73755 9887 12523 88212 112364 28378 131033 63099 102930 78232 166326 42025 145005 26580 85545 114549 71238 19865 71364 183284 21738 132799 134266 129286 50677 118977 17635 110174 85984 57815 147687 131631...
output:
Case 1: 1 Case 2: 2 Case 1: 7 Case 3: 10 Case 2: 16 Case 1: 18 Case 1: 32 Case 2: 37 Case 1: 39 Case 3: 42 Case 2: 45 Case 1: 46 Case 2: 47 Case 2: 49 Case 2: 51 Case 2: 53 Case 3: 62 Case 1: 63 Case 2: 70 Case 1: 78 Case 1: 79 Case 3: 83 Case 3: 85 Case 1: 91 Case 3: 94 Case 3: 95 Case 2: 96 Case 2...
result:
wrong answer 1st lines differ - expected: '353453 235794 271414 264379 23...385 242018 240421 239405 231243', found: 'Case 1: 1'
Subtask #9:
score: 0
Wrong Answer
Test #122:
score: 0
Wrong Answer
time: 1272ms
memory: 72448kb
input:
100000 1 173206 29172 157020 147149 12220 145352 172784 36710 183091 187710 142752 23844 81586 161419 87210 154300 66402 175548 62953 30212 149421 117646 193418 118516 177795 115642 176042 126287 14433 17937 105013 14605 143898 132929 143591 115108 42509 177469 90041 168554 70665 11736 145789 93906 ...
output:
Case 1: 3 Case 2: 4 Case 1: 8 Case 2: 11 Case 1: 14 Case 3: 17 Case 2: 28 Case 3: 29 Case 1: 31 Case 2: 35 Case 3: 36 Case 1: 37 Case 2: 41 Case 3: 44 Case 1: 46 Case 2: 48 Case 3: 51 Case 3: 64 Case 1: 72 Case 1: 75 Case 3: 78 Case 2: 80 Case 3: 81 Case 2: 83 Case 1: 89 Case 3: 93 Case 3: 96 Case 2...
result:
wrong answer 1st lines differ - expected: '246499', found: 'Case 1: 3'
Subtask #10:
score: 0
Wrong Answer
Test #140:
score: 0
Wrong Answer
time: 2486ms
memory: 76700kb
input:
100000 10 57693 110342 28705 133926 61784 186038 51305 155569 48140 115185 14169 141018 165711 24907 12001 165455 122449 21315 93989 187573 166405 193098 3306 189403 2421 23963 28619 50447 23589 121975 112280 17930 2499 90579 103377 113266 119659 153038 102862 35946 124741 136376 146205 141476 11481...
output:
Case 2: 2 Case 3: 11 Case 1: 13 Case 3: 14 Case 2: 21 Case 3: 23 Case 2: 27 Case 2: 28 Case 2: 31 Case 3: 32 Case 2: 34 Case 3: 39 Case 3: 45 Case 1: 48 Case 1: 58 Case 1: 66 Case 3: 68 Case 1: 72 Case 3: 73 Case 1: 77 Case 2: 88 Case 1: 90 Case 3: 91 Case 1: 93 Case 3: 99 Case 1: 103 Case 1: 108 Ca...
result:
wrong answer 1st lines differ - expected: '413064 268881 264857 258053 25...166 256016 249141 267637 271386', found: 'Case 2: 2'