QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#300919#7967. 二进制defyers#WA 4ms52728kbC++203.4kb2024-01-09 00:39:552024-01-09 00:39:55

Judging History

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

  • [2024-01-09 00:39:55]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:52728kb
  • [2024-01-09 00:39:55]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

#define int long long
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

using ll = long long;
using LL = long long;

const int N = 1 << 20;

struct BIT{
	int bit[N];
	void add(int p, int x){ for(int i = p; i < N; i += i & -i) bit[i] += x; }
	int qry(int p){ int ret = 0; for(int i = p; i; i -= i & -i) ret += bit[i]; return ret; }
	int bs(int v){ int ret = 0, s = 0; for(int j = 19; j >= 0; j--) if(ret + (1 << j) < N && s + bit[ret + (1 << j)] < v) ret += (1 << j), s += bit[ret]; return ret + 1; }
} bit;

int n; 
bool a[N], remed[N];
int l[N], r[N], c[N];
vector<int> S[N], T[N];


int len(int l){
	int x = 0;
	while(l){
		x++;
		l /= 2;
	}
	return x;
}

int L[20], R[20];
int cur_len, MAGIC;

void try_add(int u, int idx){
	if(len(u) != MAGIC) return;
	S[u].push_back(idx);
}
void try_rem(int u, int idx){
	if(len(u) != MAGIC) return;
	T[u].push_back(idx);
}

void rem(int x){
	int sl = 0, sr = 0;
	for(int y = l[x], tr = 0; y != 0 && tr < 20; tr++){
		L[tr] = y; y = l[y]; sl++;
	}
	for(int y = r[x], tr = 0; y != n + 1 && tr < 20; tr++){
		R[tr] = y; y = r[y]; sr++;
	}

	for(int i = sl - 1; i >= 0; i--){
		if(!a[L[i]]) continue;
		int v = 1;
		for(int j = i - 1; j >= 0; j--){
			v = v * 2 + a[L[j]];
		}
		// NOT choose middle
		int u = v;
		for(int j = 0; j < sr; j++){
			u = u * 2 + a[R[j]];
			if(u >= N) break;
			try_add(u, L[i]);
		}
		// DOES choose middle
		u = v * 2 + a[x];
		try_rem(u, L[i]);
		// cout << "R " << u << ' ' << L[i] << endl;
		for(int j = 0; j < sr; j++){
			u = u * 2 + a[R[j]];
			if(u >= N) break;
			// cout << "ADD " << u << ' ' << L[i] << endl;
			try_rem(u, L[i]);
		}
	}

	if(a[x]){
		int u = a[x];
		try_rem(u, x);
		for(int j = 0; j < sr; j++){
			u = u * 2 + a[R[j]];
			if(u >= N) break;
			try_rem(u, x);
		}
	}
	bit.add(x, 1);
	l[r[x]] = l[x];
	r[l[x]] = r[x];
}


void solve(int TC) {
	cin >> n;
	for(int i = 0; i <= n + 1; i++){
		l[i] = i - 1;
		r[i] = i + 1;
	}
	l[0] = 0, r[n + 1] = n + 1;
	string s; cin >> s;
	for(int i = 1; i <= n; i++){
		a[i] = s[i - 1] == '1';
	}

	// for(int l = 1; l <= n; l++){
	// 	for(auto u : S[l]) cout << u << ' '; cout << '\n';
	// }
	for(int x = 1; x < N; x *= 2){
		MAGIC = len(x);
		cout << MAGIC << endl;
		for(int i = 1; i <= n; i++){
			if(remed[i] || a[i] == 0) continue;
			int v = 0, y = i;
			for(int j = 0; j < 20 && y <= n; j++){
				v = v * 2 + a[y];
				if(len(v) == MAGIC) S[v].push_back(i);
			}
		}
		for(int l = x; l <= min(n, x * 2 - 1); l++){
			cur_len = l;
			sort(S[l].begin(), S[l].end());
			sort(T[l].begin(), T[l].end());
			int cnt = S[l].size() - T[l].size();
			if(cnt == 0){
				cout << -1 << ' ' << 0 << '\n';
			}else{
				int idx = 0;
				assert(cnt > 0);
				// cout << "S T" << endl;
				// for(auto x : S[l]) cout << x << ' '; cout << '\n';
				// for(auto x : T[l]) cout << x << ' '; cout << '\n';
				while(idx < T[l].size() && S[l][idx] == T[l][idx]){
					++idx;
				}
				int pos = S[l][idx];
				cout << pos - bit.qry(S[l][idx] - 1) << ' ' << cnt << '\n';
				for(int j = 0; j < len(l); j++){
					rem(pos); pos = r[pos];
				}
			}
		}
	}
	
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++) {
		solve(i);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 52728kb

input:

20
01001101101101110010

output:

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

result:

wrong answer 1st lines differ - expected: '2 11', found: '1'