QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#180566#5459. Goose, goose, DUCK?HTensorCompile Error//C++143.1kb2023-09-16 00:17:362023-09-16 00:17:36

Judging History

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

  • [2023-09-16 00:17:36]
  • 评测
  • [2023-09-16 00:17:36]
  • 提交

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 <= 1e6; 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);
			assert() 
//			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

In file included from /usr/include/c++/11/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:1:
answer.code: In function ‘void solve()’:
answer.code:106:25: error: expected primary-expression before ‘)’ token
  106 |                         assert()
      |                         ^~~~~~