QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87957 | #5242. Płótno [B] | anhduc2701 | 0 | 2613ms | 76848kb | C++23 | 6.3kb | 2023-03-14 21:48:39 | 2023-03-14 21:48:42 |
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[a+1].pb({-1,{a,bb-1}});
p[a+1].pb({1,{b,bb-1}});
p[b+1].pb({-1,{b,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[a+1].pb({-1,{a,aa-1}});
p[a+1].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: 11ms
memory: 50364kb
input:
10 1 6 18 4 17 1 8 7 13 5 10 2 20 3 11 15 12 19 16 14 9
output:
57
result:
wrong answer 1st lines differ - expected: '58', found: '57 '
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 1
Accepted
time: 4ms
memory: 50336kb
input:
2 4 1 2 4 3
output:
10 0 0 0
result:
ok single line: '10 0 0 0 '
Test #17:
score: 0
Accepted
time: 13ms
memory: 50340kb
input:
2 4 1 4 2 3
output:
10 0 0 0
result:
ok single line: '10 0 0 0 '
Test #18:
score: 0
Accepted
time: 13ms
memory: 50164kb
input:
2 4 1 4 3 2
output:
8 2 0 0
result:
ok single line: '8 2 0 0 '
Test #19:
score: -1
Wrong Answer
time: 16ms
memory: 50344kb
input:
10 10 12 17 9 11 8 6 13 15 20 16 14 19 4 18 2 5 7 1 3 10
output:
39 63 85 19 4 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '54 70 70 14 2 0 0 0 0 0', found: '39 63 85 19 4 0 0 0 0 0 '
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 21ms
memory: 50456kb
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:
821 506 734 619 529 752 806 914 930 883
result:
wrong answer 1st lines differ - expected: '1781 1446 1564 1298 1500 1585 1516 1761 1659 1513', found: '821 506 734 619 529 752 806 914 930 883 '
Subtask #4:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 1358ms
memory: 72468kb
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:
189481
result:
wrong answer 1st lines differ - expected: '335745', found: '189481 '
Subtask #5:
score: 0
Wrong Answer
Test #61:
score: 0
Wrong Answer
time: 206ms
memory: 54748kb
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:
18713
result:
wrong answer 1st lines differ - expected: '58709', found: '18713 '
Subtask #6:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 395ms
memory: 55624kb
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:
33553 31272 8578 8584 13633 11989 12587 14936 8979 8140
result:
wrong answer 1st lines differ - expected: '62119 52465 66066 51757 46662 46349 56343 50160 45653 51054', found: '33553 31272 8578 8584 13633 11989 12587 14936 8979 8140 '
Subtask #7:
score: 0
Wrong Answer
Test #96:
score: 0
Wrong Answer
time: 1432ms
memory: 72624kb
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:
293965
result:
wrong answer 1st lines differ - expected: '493945', found: '293965 '
Subtask #8:
score: 0
Wrong Answer
Test #109:
score: 0
Wrong Answer
time: 2613ms
memory: 76848kb
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:
167394 63270 79232 42250 60849 42338 42814 40911 31342 42629
result:
wrong answer 1st lines differ - expected: '353453 235794 271414 264379 23...385 242018 240421 239405 231243', found: '167394 63270 79232 42250 60849 42338 42814 40911 31342 42629 '
Subtask #9:
score: 0
Wrong Answer
Test #122:
score: 0
Wrong Answer
time: 1354ms
memory: 72596kb
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:
80368
result:
wrong answer 1st lines differ - expected: '246499', found: '80368 '
Subtask #10:
score: 0
Wrong Answer
Test #140:
score: 0
Wrong Answer
time: 2520ms
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:
260262 56523 87954 64935 61226 73032 82998 65691 69381 89264
result:
wrong answer 1st lines differ - expected: '413064 268881 264857 258053 25...166 256016 249141 267637 271386', found: '260262 56523 87954 64935 61226 73032 82998 65691 69381 89264 '