QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605079#5459. Goose, goose, DUCK?tosaniaWA 546ms75264kbC++142.8kb2024-10-02 15:24:052024-10-02 15:24:05

Judging History

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

  • [2024-10-02 15:24:05]
  • 评测
  • 测评结果:WA
  • 用时:546ms
  • 内存:75264kb
  • [2024-10-02 15:24:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int T, n, k, a[N], last[N],head[N], nex[N], al[N], now[N], fir[N],ans;
struct node {
	int l, r, z, laze_tag, num;
};
class segtree {
public:
	node a[4 * N];
	void build(int now, int l, int r) {
		a[now].num = r - l + 1;
		a[now].z = 0;
		a[now].l = l;
		a[now].r = r;
		if (l == r) {
			return ;
		}
		int mid = (l + r) / 2;
		build(now * 2, l, mid);
		build(now * 2+1, mid + 1, r);
	}
	void add(int now, int l, int r, int z) {
		if (a[now].l > r || a[now].r < l) {
			return ;
		}
		else if (a[now].l == a[now].r) {
			a[now].z += z;
			a[now].num = 1;
		}
		else if (a[now].l >= l && a[now].r <= r) {
			a[now].laze_tag += z;
		}
		else {
			add(now * 2, l, r, z);
			add(now * 2 + 1, l, r, z);
			if (a[now * 2].z + a[now * 2].laze_tag == a[now * 2 + 1].z + a[now * 2 + 1].laze_tag) {
				a[now].z = a[now * 2].z + a[now * 2].laze_tag;
				a[now].num = a[now * 2].num + a[now * 2 + 1].num;
			}
			else if (a[now * 2].z + a[now * 2].laze_tag < a[now * 2 + 1].z + a[now * 2 + 1].laze_tag) {
				a[now].z = a[now * 2].z + a[now * 2].laze_tag;
				a[now].num = a[now * 2].num;
			}
			else {
				a[now].z = a[now * 2 + 1].z + a[now * 2 + 1].laze_tag;
				a[now].num = a[now * 2 + 1].num;
			}
		}
	}
	int query(int now, int l, int r, int mu) {
		if (a[now].l > r || a[now].r < l) {
			return 0;
		}
		else if (a[now].l == a[now].r && a[now].z == mu) {
			return 1;
		}
		else if (a[now].l >= l && a[now].r <= r) {
			if (a[now].z + a[now].laze_tag == mu) {
				return a[now].num;
			}
			else return 0;
		}
		else {
			return query(now * 2, l, r, mu - a[now].laze_tag) + query(now * 2+1, l, r, mu - a[now].laze_tag);
		}
	}
	void print(int now){
		cout<<now<<" "<<a[now].l<<" "<<a[now].r<<" "<<a[now].z<<" "<<a[now].laze_tag<<" "<<a[now].num<<endl;
		if(a[now].l!=a[now].r){
			print(now*2);
			print(now*2+1);
		}
	}
} tree;
inline int read() {
	int al = 0, fh = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-')
			al = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		al = al * 10 + ch - '0';
		ch = getchar();
	}
	return al * fh;
}
signed main() {
	n = read();
	k = read();
	tree.build(1,1,n);
	// tree.add(1,1,1,1)
	// tree.add(1,1,2,1);
	// cout<<tree.query(1,1,3,0);
	// return 0;
	for (int i = 1; i <= n; i++) {
		a[i] = read();
	}
	for(int i=n;i>=1;i--){
		nex[i]=head[a[i]];
		head[a[i]]=i;
	}
	for (int i = 1; i <= n; i++) {
		if (al[a[i]] < k-1) {
			al[a[i]]++;
		}
		else if (al[a[i]] == k-1) {
			last[a[i]]=1;
			now[a[i]]=head[a[i]];
			tree.add(1,1,now[a[i]],1);
			al[a[i]]++;
		}
		else{
			tree.add(1,last[a[i]],now[a[i]],-1);
			last[a[i]]=now[a[i]]+1;
			now[a[i]]=nex[now[a[i]]];
			tree.add(1,last[a[i]],now[a[i]],1);
		}
		ans+=tree.query(1,1,i,0);
	}
	cout<<ans;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11864kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 0ms
memory: 11884kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 2ms
memory: 15984kb

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:

4309

result:

ok 1 number(s): "4309"

Test #4:

score: 0
Accepted
time: 0ms
memory: 16036kb

input:

1000 100
144044 144044 606320 144044 144044 653289 606320 606320 606320 144044 653289 606320 144044 606320 144044 653289 606320 653289 144044 144044 606320 606320 606320 144044 606320 653289 653289 144044 606320 606320 606320 606320 606320 606320 606320 606320 653289 606320 653289 606320 653289 6532...

output:

494331

result:

ok 1 number(s): "494331"

Test #5:

score: 0
Accepted
time: 3ms
memory: 20184kb

input:

1000 2
37158 712133 695735 352502 37158 111876 979836 322207 850 170255 712133 37158 68113 170255 269273 322207 644692 127744 575843 269273 352502 68113 166126 413274 111876 575843 704107 695735 37158 604776 127744 269273 166126 704107 850 111876 352502 979836 850 850 712133 850 979836 575843 704107...

output:

382010

result:

ok 1 number(s): "382010"

Test #6:

score: 0
Accepted
time: 0ms
memory: 20408kb

input:

1000 1
439144 11249 309118 842057 842057 938195 823723 842057 589439 914850 938195 455713 91595 938195 553566 761181 553566 70966 455713 439144 704849 11249 11249 236580 320993 933831 872377 589439 435476 558991 914850 690853 482410 690853 715546 155003 435476 155003 435476 435476 842057 236580 7096...

output:

341042

result:

ok 1 number(s): "341042"

Test #7:

score: 0
Accepted
time: 0ms
memory: 23684kb

input:

1000 1
675227 756097 647871 465683 473815 162625 396802 61313 758469 968915 283015 326083 86904 672294 145904 621859 346020 237440 669779 282692 626616 722910 999031 141389 440533 971280 807058 346648 405103 669779 463968 214284 50833 661085 826455 991362 984243 704592 426668 998421 949882 147122 72...

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 518ms
memory: 75264kb

input:

1000000 1
420242 544222 171447 777913 987553 724009 569564 35971 931705 898245 672004 267555 967920 126950 627536 979230 592634 345070 437097 838283 124796 525563 988560 362647 502828 510728 538451 742569 327219 207978 943947 684879 278534 669721 356340 258535 85663 265714 956295 291196 419333 19692...

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: -100
Wrong Answer
time: 546ms
memory: 68104kb

input:

1000000 1
559660 917135 718911 137428 227265 619698 582978 634509 968207 398589 647945 907790 647945 453872 267596 39233 647945 225421 404411 559660 401213 907790 765663 401213 339252 723380 907790 619698 896672 907790 58034 686103 455430 917135 686103 225421 619698 203386 893988 438096 75622 401213...

output:

1469858554

result:

wrong answer 1st numbers differ - expected: '499686064890', found: '1469858554'