QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179116#5459. Goose, goose, DUCK?HTensorWA 8ms61236kbC++143.1kb2023-09-14 18:13:452023-09-14 18:13:45

Judging History

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

  • [2023-09-14 18:13:45]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:61236kb
  • [2023-09-14 18:13:45]
  • 提交

answer

#include <bits/stdc++.h>
#define d(x) cerr << #x << " => " << x << endl
#define dd(x) cerr << #x << endl
#define D cerr << "Passed [" << __FUNCTION__ << "] on line " << __LINE__ << endl
#define ms(x) memset(x, 0, sizeof x)
#define int long long

template<typename T> std::istream& operator>>(std::istream& is, std::vector<T>& v) { for (auto& i : v) is >> i; return is; }
template<typename T> std::ostream& operator<<(std::ostream& os, std::vector<T>& v) { for (auto& i : v) os << i << " "; return os; }
template<typename T> auto dbug(const std::initializer_list<T>& a) { for (auto& i : a) std::cout << i << " "; std::cout << "\n"; }

using namespace std;

const int inf = 0x3f3f3f3f3f3f3f3f;

int rd() {
	int f = 1, val = 0; char ch = getchar();
	while(!isdigit(ch)) f = (ch == '-' ? -1 : 1), ch = getchar();
	while(isdigit(ch)) val = val * 10 + ch - '0', ch = getchar();
	return f * val;
}

const int N = 2e6 + 5;

class segmentTree {
#define MID int mid = (l + r) / 2;
#define lson l, mid, x << 1
#define rson mid + 1, r, x << 1 | 1
public:
	static const int N = ::N;
	int sum[N << 2], lzy[N << 2], minx[N << 2], num[N << 2];
	
	void build(int l, int r, int x) {
		if(l == r) {
			sum[x] = 0;
			lzy[x] = 0;
			minx[x] = 0; num[x] = 1;
			return ;
		}
		MID;
		build(lson); build(rson);
		up(x);
	}
	
	void down(int l, int r, int x) {
		if(lzy[x] == 0) return ;
		MID;
		sum[x << 1] += lzy[x] * (mid - l + 1);
		sum[x << 1 | 1] += lzy[x] * (r - mid);
		minx[x << 1] += lzy[x];
		minx[x << 1 | 1] += lzy[x];
		lzy[x << 1] += lzy[x];
		lzy[x << 1 | 1] += lzy[x];
		lzy[x] = 0;
	}
	
	void up(int x) {
		sum[x] = sum[x << 1] + sum[x << 1 | 1];
		if(minx[x << 1] < minx[x << 1 | 1]) {
			num[x] = num[x << 1];
		} else if(minx[x << 1] == minx[x << 1 | 1]){
			num[x] = num[x << 1] + num[x << 1 | 1];
		} else {
			num[x] = num[x << 1 | 1];
		}
		minx[x] = min(minx[x << 1], minx[x << 1 | 1]);
	}
	
	void add(int l, int r, int x, int p, int q, int v) {
		if(p <= l && r <= q) {
			sum[x] += (r - l + 1) * v;
			minx[x] += v;
			lzy[x] += v;
			return ;
		}
		MID; down(l, r, x); 
		if(p <= mid) add(lson, p, q, v);
		if(q > mid) add(rson, p, q, v);
		up(x);
	}
} st;

vector<int> pos[N];
int ti[N], a[N];

void solve() {
	int n = rd(), k = rd();
	st.build(1, n, 1);
	for(int i = 1; i <= n; i++) pos[i].push_back(0);
	for(int i = 1; i <= n; i++) {
		a[i] = rd();
		ti[i] = pos[a[i]].size();
		pos[a[i]].push_back(i);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(ti[i] >= k) {
			int u = ti[i], v = a[i];
			if(u != k) {
				st.add(1, n, 1, pos[v][u - k - 1] + 1, pos[v][u - k], -1);
				// cout << pos[v][u - k - 1] + 1 << " " << pos[v][u - k] << endl;
			}
//			cout << pos[v][u - k] + 1 << " " <<  pos[v][u - k + 1] << endl;
			st.add(1, n, 1, pos[v][u - k] + 1, pos[v][u - k + 1], 1);
//			cout << "contrib" << i - (n - st.num[1]) << " " << st.num[1] << endl;
		} 
		int v = (st.minx[1] == 0 ? st.num[1] : 0);
		ans += i - (n - v);
	}
	printf("%lld\n", ans);
}

signed main() {
	int T = 1;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 59192kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 61168kb

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:

4325

result:

wrong answer 1st numbers differ - expected: '4309', found: '4325'