QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87967#5242. Płótno [B]anhduc27010 2659ms77368kbC++236.4kb2023-03-14 21:59:042023-03-14 21:59:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-14 21:59:06]
  • 评测
  • 测评结果:0
  • 用时:2659ms
  • 内存:77368kb
  • [2023-03-14 21:59:04]
  • 提交

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";
    		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[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<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[a+1].pb({-1,{a,b-1}});
    		p[bb+1].pb({1,{b,n}});
    		p[a+1].pb({-1,{b,n}});
    		p[a+1].pb({1,{b,n}});
    		p[b+1].pb({-1,{b,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[a+1].pb({-1,{a,n}});
    		p[a+1].pb({1,{b,n}});
    		p[b+1].pb({-1,{b,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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 1
Accepted
time: 3ms
memory: 50296kb

input:

10 1
6 18 4 17 1 8 7 13 5 10
2 20 3 11 15 12 19 16 14 9

output:

58 

result:

ok single line: '58 '

Test #2:

score: -1
Wrong Answer
time: 10ms
memory: 50344kb

input:

50 1
23 16 49 25 71 84 82 43 70 61 75 92 24 78 48 66 100 9 81 44 91 22 7 51 37 33 10 41 62 26 55 32 47 54 3 31 40 68 8 77 73 59 96 38 50 97 46 99 60 42
45 53 88 27 79 39 63 29 89 58 15 36 64 18 93 76 98 65 11 87 95 67 21 6 80 28 83 74 5 72 13 20 52 17 85 56 4 94 57 86 12 35 90 69 2 34 14 1 30 19

output:

195 

result:

wrong answer 1st lines differ - expected: '136', found: '195 '

Subtask #2:

score: 0
Wrong Answer

Test #16:

score: 1
Accepted
time: 16ms
memory: 50248kb

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: 12ms
memory: 50336kb

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: 3ms
memory: 50228kb

input:

2 4
1 4
3 2

output:

8 2 0 0 

result:

ok single line: '8 2 0 0 '

Test #19:

score: 0
Accepted
time: 4ms
memory: 50276kb

input:

10 10
12 17 9 11 8 6 13 15 20 16
14 19 4 18 2 5 7 1 3 10

output:

54 70 70 14 2 0 0 0 0 0 

result:

ok single line: '54 70 70 14 2 0 0 0 0 0 '

Test #20:

score: -1
Wrong Answer
time: 7ms
memory: 50348kb

input:

50 10
54 43 68 23 49 12 45 71 75 50 74 29 24 15 7 65 78 3 51 10 42 80 58 47 32 39 37 91 88 1 26 63 38 2 67 94 70 60 98 48 13 34 85 5 61 55 11 89 72 40
53 16 82 20 76 17 46 84 36 9 30 8 25 44 93 86 73 6 35 64 14 79 18 81 57 92 56 97 27 100 31 62 69 52 4 96 66 59 19 99 87 41 95 21 83 90 28 77 22 33

output:

136 138 156 177 177 177 191 212 245 234 

result:

wrong answer 1st lines differ - expected: '124 134 147 166 169 173 179 205 220 225', found: '136 138 156 177 177 177 191 212 245 234 '

Subtask #3:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 14ms
memory: 50380kb

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:

1966 1558 1733 1571 1469 1670 1716 1811 1813 1725 

result:

wrong answer 1st lines differ - expected: '1781 1446 1564 1298 1500 1585 1516 1761 1659 1513', found: '1966 1558 1733 1571 1469 1670 1716 1811 1813 1725 '

Subtask #4:

score: 0
Wrong Answer

Test #51:

score: 0
Wrong Answer
time: 1382ms
memory: 72908kb

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:

427035 

result:

wrong answer 1st lines differ - expected: '335745', found: '427035 '

Subtask #5:

score: 0
Wrong Answer

Test #61:

score: 0
Wrong Answer
time: 216ms
memory: 54920kb

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:

65848 

result:

wrong answer 1st lines differ - expected: '58709', found: '65848 '

Subtask #6:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 416ms
memory: 55680kb

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:

80824 74919 52223 52182 57225 55575 56159 58481 52574 51718 

result:

wrong answer 1st lines differ - expected: '62119 52465 66066 51757 46662 46349 56343 50160 45653 51054', found: '80824 74919 52223 52182 57225 55575 56159 58481 52574 51718 '

Subtask #7:

score: 0
Wrong Answer

Test #96:

score: 0
Wrong Answer
time: 1387ms
memory: 72796kb

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:

531583 

result:

wrong answer 1st lines differ - expected: '493945', found: '531583 '

Subtask #8:

score: 0
Wrong Answer

Test #109:

score: 0
Wrong Answer
time: 2627ms
memory: 77368kb

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:

404773 281923 297882 260897 279433 260935 261570 259525 249969 261284 

result:

wrong answer 1st lines differ - expected: '353453 235794 271414 264379 23...385 242018 240421 239405 231243', found: '404773 281923 297882 260897 27...35 261570 259525 249969 261284 '

Subtask #9:

score: 0
Wrong Answer

Test #122:

score: 0
Wrong Answer
time: 1321ms
memory: 73084kb

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:

317112 

result:

wrong answer 1st lines differ - expected: '246499', found: '317112 '

Subtask #10:

score: 0
Wrong Answer

Test #140:

score: 0
Wrong Answer
time: 2659ms
memory: 77212kb

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:

497014 274906 306347 283326 279527 291413 301345 284031 287627 307466 

result:

wrong answer 1st lines differ - expected: '413064 268881 264857 258053 25...166 256016 249141 267637 271386', found: '497014 274906 306347 283326 27...13 301345 284031 287627 307466 '